# Telling GCC to shove it

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, so the title is a little harsh, since this is an annoyance more than an actual problem, but it's still something that bugs the hell out of me! I've been working lately on "fixing" my existing code, developed with MSVC, so that it will compile with GCC (or, well, G++ in this case) in anticipation of working on some cross platform stuff in the near future. While GCC is definatly a lot more "standards compliant" (read: Anal) about niggly things like operator definitions, for the most part the conversion has gone pretty smoothly, and I've gotten it to the point where it compiles practically error/warning free under any compiler I throw my code at! (Yay!) I say practically, though, because I've got one warning left that, quite frankly, I don't want to fix. You see, I use "NULL" EVERYWHERE. A lot of my functions take in unsigned integers as a "handle" of sorts, with 0 always being a default handle for whatever resource I'm referring to. (It's a lot like OpenGL syntax-wise) I like using NULL rather than 0, since I feel it gives a better visual representation of what your doing with the particular function. And besides, NULL = 0 anyways, right? Well, GCC seems to feel that NULL should be used with and ONLY with pointers. When I compile I get two pages worth of warnings that all say something like: [Warning] converting to non-pointer type uint' from NULL and [Warning] NULL used in arithmetic To which I respond "I don't care!" (The compiler never listens though... *sigh*) So anyways, my simple question for this exessively long post is this: How can I prevent GCC from displaying these warnings? I know how to use pre-processor statements to block warnings, but unlike MSVC the IDE I'm using (Dev-C++) doesn't give me the warning code, and I haven't been able to find a code for this error online. Any ideas? Thanks! -Toji

##### Share on other sites
I've never tried this but you might be able to cast your way out of this one, cast each NULL to type.

ie.

int a = (int) NULL;

Might work, but then it involves lots of code changes. Another thought might be to see if it is possible to turn off warnings in G++ like you can in VC.

ace

##### Share on other sites
Depending on how intelligent the warning itself is you *might* be able to avoid it by redefining NULL manually. Still, I can't really come up with clever workarounds other than defining your own constant or hacking the compiler.
It just seems like certain warnings can't be disabled in GCC, at least I haven't found generic way of doing so like what VC provides (*please* give me a way of avoiding the incredibly annoying 'no newline found at end of file' warning).
Quote:
 Original post by TojiNULL = 0 anyways, right?
Not in C where it's often defined as (void *) 0.

##### Share on other sites
Quote:
 Original post by TojiI say practically, though, because I've got one warning left that, quite frankly, I don't want to fix. You see, I use "NULL" EVERYWHERE. A lot of my functions take in unsigned integers as a "handle" of sorts, with 0 always being a default handle for whatever resource I'm referring to. (It's a lot like OpenGL syntax-wise) I like using NULL rather than 0, since I feel it gives a better visual representation of what your doing with the particular function. And besides, NULL = 0 anyways, right?

Actually, the C standard says that it can be

#define NULL 0
#define NULL (void *)0

or equivalent. I think the C++ standard has a similar requirement. Note that (void *)0, (float)0, and (int)0 need not all have the same binary representation.

NULL is intended to be a null pointer constant.

Quote:
 Well, GCC seems to feel that NULL should be used with and ONLY with pointers.

Well, it is a pointer, or intended to be.

Quote:
 When I compile I get two pages worth of warnings that all say something like: [Warning] converting to non-pointer type uint' from NULLand[Warning] NULL used in arithmetic

It must've choosen to define it as (void *)0.

Quote:
 To which I respond "I don't care!" (The compiler never listens though... *sigh*)

But type safety is supposed to be one of C++'s good points...

Quote:
 So anyways, my simple question for this exessively long post is this: How can I prevent GCC from displaying these warnings? I know how to use pre-processor statements to block warnings, but unlike MSVC the IDE I'm using (Dev-C++) doesn't give me the warning code, and I haven't been able to find a code for this error online. Any ideas?

It doesn't look like GCC has an option for this. What I recommend, in order of preference (It sounded like you're using C++):

1) const uint NULL_HANDLE = 0;
2) Use the C++ convention of using 0 instead of NULL for null pointer constants (your problem is precisely the reason this convention exists).
3) #undef NULL
#define NULL 0

##### Share on other sites
Quote:
 Original post by doynax (*please* give me a way of avoiding the incredibly annoying 'no newline found at end of file' warning).

Add a newline terminator at the end of the file. It isn't very difficult, and I wish MSVC would warn me when I forget.

##### Share on other sites
Quote:
 Original post by Way WalkerIt must've choosen to define it as (void *)0.
C++ can't choose to define it as a void pointer since C++ doesn't support implicit casts from void pointers anymore (one of those typesafety guards again). This is the reason that NULL is generally considered less useful in C++ since it can't give proper warnings anymore, though GCC seems to have made it's contribution to that argument (much like it's type checks on printf format strings).

Quote:
Original post by nprz
Quote:
 Original post by doynax (*please* give me a way of avoiding the incredibly annoying 'no newline found at end of file' warning).

Add a newline terminator at the end of the file. It isn't very difficult, and I wish MSVC would warn me when I forget.
It's very easy to do *once*, but I having to put up with it continually when your favourite editor doesn't support it manually is just plain annoying.
I mean really, what's the chances for this being a problem with the editor rather than an actual ill-formed text file?

##### Share on other sites
As far as the NULL thing, its because NULL is generally reserved for pointers because NULL means nothing. A NULL pointer doesnt point to anything, 0 is not nothing. And while NULL does in fact = zero, thats not its intention, its hard to represent the concept of nothing, but NULL was close enough. Perhaps NULL isnt the best choice of naming for your default parameter.

Fix it.

##### Share on other sites
Quote:
 Original post by Anonymous PosterYour code is broken.Fix it.

Quoted for emphasis.

NULL is a semantic notion, but one not natively supported by C++ (and I personally believe that a true null keyword should be introduced to the language to put an end to this nonsense). It is not a value; it is a non-value. int * ptr = null; signifies that ptr has no pointer value assigned to it, which is semantically meaningful. int a = NULL is not meaningful, semantically; you might as well just write int a; and know that you have "garbage" in that integer.

Problem is, you shouldn't have garbage values at all. Initialize your resources, and de-initialize if necessary on destruction (which should generally coincide with going out of scope, except for memory).

So, yeah, fix your code. Make it more meaningful to you, the programmer, and to whatever poor sap ends up having to maintain it after you've moved on (which might be you six months to three years from now).

Happy hacking.

##### Share on other sites
http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html#Warning-Options
-w Inhibit all warning messages.
Warnings aren't errors. The code should still compile.

If you want a more permanent solution, do a replace on all instances of NULL with NIL and #define NIL as 0.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633297
• Total Posts
3011247
• ### Who's Online (See full list)

There are no registered users currently online

×