limits.h Sanity Issue

B

Billy Mays

Hey clc,


I am trying to use the UINT_MAX macro defined in limits.h but it doesn't
seem to be defined which I try to compile my code. I looked through my
limits.h file and found this line:

/* If we are not using GNU CC we have to define all the symbols ourself.
Otherwise use gcc's definitions (see below). */
#if !defined __GNUC__ || __GNUC__ < 2


It seems that it is expecting the compiler (gcc for me) to make the
appropriate defines, but I still get this error:

file.c: In function ‘main’:
file.c:12: error: ‘INT_MAX’ undeclared (first use in this function)


I would really prefer to not override this Macro, since I don't know all
the implications of doing so. Is there a right way to get these limits
defined?

Bill
 
E

Eric Sosman

>
I am trying to use the UINT_MAX macro defined in limits.h but it doesn't
seem to be defined which I try to compile my code. I looked through my
limits.h file and found this line:

/* If we are not using GNU CC we have to define all the symbols ourself.
Otherwise use gcc's definitions (see below). */
#if !defined __GNUC__ || __GNUC__ < 2


It seems that it is expecting the compiler (gcc for me) to make the
appropriate defines, but I still get this error:

file.c: In function ‘main’:
file.c:12: error: ‘INT_MAX’ undeclared (first use in this function)


I would really prefer to not override this Macro, since I don't know all
the implications of doing so. Is there a right way to get these limits
defined?

Yes: #include <limits.h>, as in

#include <stdio.h>
#include <limits.h>
int main(void) {
printf ("INT_MAX = %d, UINT_MAX = %u\n", INT_MAX, UINT_MAX);
return 0;
}

It's all but certain that you're doing something wrong (if INT_MAX
didn't work, people all over the globe would be shrieking about it), but
since you haven't shown any code it's hard to say what's wrong. Please
show us the code that generates the message. (Don't post a thousand-
line module; post something roughly the size of my example.)
 
B

Billy Mays

> ...
It's all but certain that you're doing something wrong (if INT_MAX
didn't work, people all over the globe would be shrieking about it), but
since you haven't shown any code it's hard to say what's wrong. Please
show us the code that generates the message. (Don't post a thousand-
line module; post something roughly the size of my example.)

Sorry, PEBCAK. I didn't see that I spelled it #inlcude and I missed the
error. The compiler error was uppercase, and the preprocessor error was
lowercase.

Is there any way to force the compiler to stop complaining immediately
after the first error?

Bill
 
E

Edward

Billy said:
Sorry, PEBCAK. I didn't see that I spelled it #inlcude and I missed the
error. The compiler error was uppercase, and the preprocessor error was
lowercase.

Is there any way to force the compiler to stop complaining immediately
after the first error?

Bill
From man gcc:
-Wfatal-errors
This option causes the compiler to abort compilation on the
first error occurred rather than trying to keep going and
printing further error messages.

-Edward
 
S

Seebs

I am trying to use the UINT_MAX macro
file.c: In function ?main?:
file.c:12: error: ?INT_MAX? undeclared (first use in this function)

Is it INT_MAX or UINT_MAX?

Try posting a sample program which illustrates your problem. Something
like:

#include <limits.h>
#include <stdio.h>

int main(void) {
printf("%u\n", UINT_MAX);
return 0;
}

-s
 
S

Seebs

Is there any way to force the compiler to stop complaining immediately
after the first error?

Not in general.

In particular, gcc is VERY widely famed for the horrible failure mode
of pointlessly continuing on long after a failed preprocessor
directive, resulting in thousands of errors that have nothing to do with
anything of significance.

I seem to recall that this is expected to be fixed in gcc 4.5.

-s
 
S

Seebs

Not all directives, but merely failed includes:

If a header named in a #include directive is not found, the compiler
exits immediately. This avoids a cascade of errors arising from
declarations expected to be found in that header being missing.

-- http://gcc.gnu.org/gcc-4.5/changes.html

Yay! It really DID make it in!

That is the single most useful thing I've done in my time as a toolchain
vendor liason. (I filed a bug with Code Sourcery, with whom we have a
support contract.)

-s
 
J

Jorgen Grahn

Sorry, PEBCAK. I didn't see that I spelled it #inlcude and I missed the
error. The compiler error was uppercase, and the preprocessor error was
lowercase.

Is there any way to force the compiler to stop complaining immediately
after the first error?

You should probably do what I did: learn the practice of reading the
warning messages starting with the first one. (Or use a tool like
Emacs or an IDE which does the same.)

/Jorgen
 
N

Nick

Seebs said:
Yay! It really DID make it in!

That is the single most useful thing I've done in my time as a toolchain
vendor liason. (I filed a bug with Code Sourcery, with whom we have a
support contract.)

The thing with the status quo is that it produces so much stuff that
your typical terminal scroll-back is filled, so you can't even find the
original error. So thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,114
Members
46,702
Latest member
VernitaGow

Latest Threads

Top