User forums > Using Code::Blocks

Segmentation fault when using pointers.

(1/1)

compiler-dev:
Hi!

/*  CodeBlocks v1.0
    GNU GCC compiler
 */

void
test( string )
char *string; /* the list of tag value items */
{
    char *s1 = "123";
   char *s2;

   s2 = string;

    while( *s1 != '\0' )
    {
        *s2 = *s1;  /* !!!  Program received signal (SIGSEGV)
                            Segmentation fault  */
        s1++;
        s2++;
    }

}

int main()
{
    char* string = "321";

    test(string);
}

Segmentation fault when using pointers.
Is it bug of CodeBlocks or GNU GCC compiler?

Thanks.

Michael:
Hello,

Which C::B revision do you use? Which OS?

Sorry, but your program do not even compile. Especially here:


--- Code: ---void
test( string )
char *string; /* the list of tag value items */
{

--- End code ---

Best wishes,
Michael

thomas:
....and it is in no way related to Code::Blocks.


EDIT:
To elaborate, you are writing to a read-only memory page, which of course causes a segmentation fault, this is normal.
Such issues, however, belong to a "C programming" or "General programming" forum, not to the Code::Blocks forums.

Bug:

--- Quote from: thomas on April 28, 2006, 01:05:24 pm ---....and it is in no way related to Code::Blocks.


EDIT:
To elaborate, you are writing to a read-only memory page, which of course causes a segmentation fault, this is normal.
Such issues, however, belong to a "C programming" or "General programming" forum, not to the Code::Blocks forums.

--- End quote ---

Sorry.
Thanks a lot.

Bug:

--- Quote from: Michael on April 28, 2006, 12:35:32 pm ---Hello,

Which C::B revision do you use? Which OS?

Sorry, but your program do not even compile. Especially here:


--- Code: ---void
test( string )
char *string; /* the list of tag value items */
{

--- End code ---

Best wishes,
Michael


--- End quote ---

Sorry.
Thanks a lot.

Navigation

[0] Message Index

Go to full version