This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C code working using CC but not with gcc


Hi Hipschman

Thanks a lot for your quick response.

This is a sample c code that i ve posted here. Actually we have 100k LOC of
such code in our application.
and we have so many such uninitialized variable in that code.

But this is code was working fine in AIX server and we ported and compiled
the same in HP we meet with Memory Fault error.

Since this code was working fine in AIX we are not supposed to make any code
change in that.

Do you have any solution for this?

Thanks.

Dan Hipschman wrote:
> 
> On Wed, Apr 16, 2008 at 09:45:37PM -0700, gkarthi29 wrote:
>> 
>> #include<stdio.h>
>> main()
>> {
>>         char *x;
>>         if (*x==NULL)
>>         {
>>                 printf("hello");
>>         }
>> }
> 
> The behaviour of the program is undefined.  'x' is not initialized,
> therefore dereferencing it may or may not cause the program to crash
> (memory fault).  The output of both CC (whatever compiler that happens
> to be) and gcc is acceptable.  If you want well-defined semantics you
> must fix your program.
> 
> (On top of 'x' not being initialized, comparing '*x', which has type
> 'char' to NULL, which is considered to be pointer value is
> questionable.)  I'm not sure exactly what you were expecting the program
> to do, so I can't really give you good suggestions on how to fix it.
> You should initialize 'x' if you plan on dereferencing it, though.
> 
> Hope that helps.
> 
> 

-- 
View this message in context: http://www.nabble.com/C-code-working-using-CC-but-not-with-gcc-tp16738838p16739128.html
Sent from the gcc - Help mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]