Re: GCC Compilation problem in HP LINUX server

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andi,

> Sorry to disappoint you :) , but the HP C/C++ compiler (for
> Itanium-based systems) allows you to control the behavior of NULL
> pointer dereferences.

I believe the context of the discussion was undefined for C (ISO 9899) or
C++ (ISO 14882).

Any compiler vendor can well-define a language undefined behavior in their
compiler (GCC itself does so on quite a few undefined behaviors), but such
vendor definition is not portable, and code which relies upon such behavior
is platform specific.

Where "platform" means "OS + particular vendor's compiler".  And maybe even
a particular version of a particular vendor's compiler, since with GCC some
of the extensions (including defining otherwise language undefined behavior)
have been deprecated and removed over time, or have had their behaviors
change slightly.

And portability is the key issue that gkarthi29 has encountered.

Regardless, this construct:
#include <stdio.h>
int main()
{
 char **variable=NULL;
 printf("Starting\n");
 fflush(stdout);
 while(*variable)
 {
  printf("Inside while\n");
  fflush(stdout);
  break;
 }
 printf("Ending\n");
 fflush(stdout);
}

... is scary.  Dereferencing a wild pointer.

At best, it will SEGV post haste.

At worse (especially on an OS without memory protection), it will fob a
memory mapped I/O register and format your hard drive.

12345678:      00000000:      ????????:
[00000000] --> [????????] --> ['?']
char**         char*          char
variable

Sincerely,
--Eljay



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux