F
FKothe
Hello together,
the program below shows a behavior i do not understand. When compiled
with the HX-UX11 c-comiler ( version B.11.11.04 ) v2.p in function
test_it0 points to an invalid adress and an attempt to write to this
pointer causes the program to exit with a core dump.
Output after compiling with HP c-compiler:
1. ffffff78
1. 7eff3358
When compiled with the gcc compiler the functions test_it0 and
test_it1 are working in the same ( correct ) manner.
Output when compiled with gcc:
1. 800003fffeff3730
1. 800003fffeff3730
After moving the memset command just before the printff command it
also works ok with both compilers. Even if you comment out the line
"static char BLANK_VTRNR[2] = " ";" both functions are working.
Unfortunately i found this Problem while searching for the reason of a
program crash in a larger project. Thus i cant change to another
compiler and the described work araunds ( comment out af the
declaration, moving the memset command ) does not lead to the same
effect as in this small program.
Any comment is rather appreciated.
Thanks in Advance.
---------/snip --------------------
extern void *memset(void *, int, unsigned long);
static char BLANK_VTRNR[2] = " ";
struct s1{ char c[ 81 ]; };
struct s2{ void *p; };
void test_it0( void )
{
struct s1 v1;
memset( (void*)&v1, 0, sizeof( struct s1 ) );
struct s2 v2 = { &v1.c };
printf( "1. %lx\n", v2.p );
/*
strcpy( v2.p, "Hallo ich schreibe mal was rein.." );
printf( "%s\n", v2.p );
*/
}
void test_it1(void)
{
struct s1 v1;
struct s2 v2= { &v1.c };
printf( "1. %lx\n", v2.p );
/*
strcpy( v2.p, "Hallo ich schreibe mal was rein.." );
printf( "%s\n", v2.p );
*/
}
void main ()
{
test_it0();
test_it1();
}
------------/snap/---------------
the program below shows a behavior i do not understand. When compiled
with the HX-UX11 c-comiler ( version B.11.11.04 ) v2.p in function
test_it0 points to an invalid adress and an attempt to write to this
pointer causes the program to exit with a core dump.
Output after compiling with HP c-compiler:
1. ffffff78
1. 7eff3358
When compiled with the gcc compiler the functions test_it0 and
test_it1 are working in the same ( correct ) manner.
Output when compiled with gcc:
1. 800003fffeff3730
1. 800003fffeff3730
After moving the memset command just before the printff command it
also works ok with both compilers. Even if you comment out the line
"static char BLANK_VTRNR[2] = " ";" both functions are working.
Unfortunately i found this Problem while searching for the reason of a
program crash in a larger project. Thus i cant change to another
compiler and the described work araunds ( comment out af the
declaration, moving the memset command ) does not lead to the same
effect as in this small program.
Any comment is rather appreciated.
Thanks in Advance.
---------/snip --------------------
extern void *memset(void *, int, unsigned long);
static char BLANK_VTRNR[2] = " ";
struct s1{ char c[ 81 ]; };
struct s2{ void *p; };
void test_it0( void )
{
struct s1 v1;
memset( (void*)&v1, 0, sizeof( struct s1 ) );
struct s2 v2 = { &v1.c };
printf( "1. %lx\n", v2.p );
/*
strcpy( v2.p, "Hallo ich schreibe mal was rein.." );
printf( "%s\n", v2.p );
*/
}
void test_it1(void)
{
struct s1 v1;
struct s2 v2= { &v1.c };
printf( "1. %lx\n", v2.p );
/*
strcpy( v2.p, "Hallo ich schreibe mal was rein.." );
printf( "%s\n", v2.p );
*/
}
void main ()
{
test_it0();
test_it1();
}
------------/snap/---------------