0

I am porting AIX code to Linux. I encountered some code which compares char to NULL on AIX xlc compiler. The same code gives compile error on Linux.

There is code which compares double with NULL ( d != NULL).

Could somebody explain the semantics of comparing char or double to NULL on AIX(xlc).

Chandu
  • 1,837
  • 7
  • 30
  • 51
  • 1
    By "char" do you mean a variable declared as `char` and not a pointer like `char *`? What errors do you get? What informational notes do the compiler tell you? Do the XLC compiler only compile C code, or is this C++ code? – Some programmer dude Jan 22 '16 at 12:14
  • There is nothing special with NULL on AIX/xlC. Simply bad code. – Lorinczy Zsigmond Jan 22 '16 at 12:15
  • What Lorinczy means is covener's answer - NULL is defined loosely instead of strictly. So your comparison to char is just checking the equivalent of `d != '\0'` which is what you should change your code to use. – Jesse Chisholm Jan 26 '16 at 20:06

1 Answers1

3

With xlc on AIX, "NULL" is a macro for "0" instead of "(void *)0" so the comparison after the preprocessor runs is valid for char/int/double.

You can see this with xlc -E or gcc -E on your code.

Never use this for anything -- it's just trivia. Fix your code to not use NULL in non-pointer context.

covener
  • 17,402
  • 2
  • 31
  • 45