Why is MAXINT doubly defined in system include files

M

Marc Ferry

I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had
no response. As this problem might be present on other OSes than HP-UX
10.20, I crosspost it here, in the hope of getting an answer.

*************************

In C/C++ system include files on HP-UX 10.20,
/usr/include/values.h defines macro MAXINT as (~HIBITI)
/usr/include/sys/param.h defines macro MAXINT as 0x7fffffff

Why is that so ?
I understand that the final value is the same.
But as my program happens to include both values.h and param.h, I get
the following error (future) with aCC:

Error (future) 129: "/usr/include/values.h", line 27 # Redefinition of
macro 'MAXINT' differs from previous definition
at ["/usr/include/sys/param.h", line 45].
#define MAXINT (~HIBITI)
^^^^^^
Warning: 1 future errors were detected and ignored. Add a '+p'
option to detect and fix them before they become fatal errors in a
future release. Behavior of this ill-formed program is not guaranteed to
match that of a well-formed program

I cannot change the libraries (which include values.h and param.h) used
by my program because I don't own them. I don't want to use compile
option +W129 because it would suppress this particular future error but
also all the others.

Is there a simple trick to avoid this error ?

I noticed that the problem has been fixed on HP-UX 11i. Indeed, values.h
defines MAXINT only if it is not already defined:
#ifndef MAXINT
#define MAXINT ((int)(~(unsigned int)HIBITI))
#endif /** MAXINT **/

Thanks for your advice.
Marc Ferry
 
T

tom_usenet

I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had
no response. As this problem might be present on other OSes than HP-UX
10.20, I crosspost it here, in the hope of getting an answer.

This newsgroup is for issues relating to ISO standard C++ (or C for
the crosspost). This clearly isn't the right place,
comp.unix.programmer would be slighly closer. But if you can't get an
answer on HP related newsgroups, you should contact HP directly, since
there's no where else to post such questions.
*************************

In C/C++ system include files on HP-UX 10.20,
/usr/include/values.h defines macro MAXINT as (~HIBITI)
/usr/include/sys/param.h defines macro MAXINT as 0x7fffffff

MAXINT isn't a standard macro, the standard macro is INT_MAX, from
Why is that so ?

Presumably a bug. Have you asked HP?

Tom
 
N

Nick Austin

In C/C++ system include files on HP-UX 10.20,
/usr/include/values.h defines macro MAXINT as (~HIBITI)
/usr/include/sys/param.h defines macro MAXINT as 0x7fffffff

Why is that so ?
I understand that the final value is the same.
But as my program happens to include both values.h and param.h, I get
the following error (future) with aCC:

Error (future) 129: "/usr/include/values.h", line 27 # Redefinition of
macro 'MAXINT' differs from previous definition

#include <values.h>
#undef MAXINT
#include <sys/param.h>

Nick.
 
M

Marc Ferry

Nick said:
#include <values.h>
#undef MAXINT
#include <sys/param.h>

Question: Where should I put these lines ?

Remember: I cannot change the includes done by the libraries because I
don't own them (external product). And I doubt that both values.h and
param.h includes are in the same library.

Could you be more precise ?

Thx anyway.
 
M

Marc Ferry

tom_usenet said:
This newsgroup is for issues relating to ISO standard C++ (or C for
the crosspost). This clearly isn't the right place,
comp.unix.programmer would be slighly closer. But if you can't get an
answer on HP related newsgroups, you should contact HP directly, since
there's no where else to post such questions.

Don't you mix up with comp.std.c++ ?
MAXINT isn't a standard macro, the standard macro is INT_MAX, from
<limits.h>.

I know that very well. I never use MAXINT in my code.
But I cannot change the libraries that include MAXINT because they are
commercial ones : I don't have the source code.
I must do with them anyway.

My question was only : is there a special (simple) trick to solve the pb ?

BTW, have a look at values.h & param.h and you'll see that MAXINT _is_
defined as a macro.
Presumably a bug. Have you asked HP?

Not yet. I am going to look for my support contract with HP (if I have one).

Thanks for your advice.
Marc
 
J

Joona I Palaste

Marc Ferry <[email protected]> scribbled the following
Don't you mix up with comp.std.c++ ?

Assuming s/c++/c/, the answer is still no. The comp.lang.c{++}
newsgroups are for discussing programming in the ISO C{++} languages.
The comp.std.c{++} newsgroups, OTOH, are for discussing the *actual
standard documents*.
For example:
Typical comp.lang.c question: "Is it safe to call free() with a NULL
argument?"
Typical comp.std.c question: "The C standard says SHALL in item
28.3.5 of chapter 19. Shouldn't that be SHOULD?"
 
A

Alex

Marc Ferry said:
Question: Where should I put these lines ?

Add the #undef somewhere between the clashing #include directives in your
own source (or header) file.

Alex
 
A

Arthur J. O'Dwyer

In C/C++ system include files on HP-UX 10.20,
/usr/include/values.h defines macro MAXINT as (~HIBITI)
/usr/include/sys/param.h defines macro MAXINT as 0x7fffffff


The "canonical" workaround (according to Google) is simply to
change 'MAXINT' to something else in one of the headers, or add
guards like so:

#ifndef MAXINT
#define MAXINT foo
#endif

inside both of the headers.

I noticed that the problem has been fixed on HP-UX 11i. Indeed, values.h
defines MAXINT only if it is not already defined:
#ifndef MAXINT
#define MAXINT ((int)(~(unsigned int)HIBITI))
#endif /** MAXINT **/

Well, that's the fix you should use, then.
Perhaps you don't have write access to /usr/include -- in
that case, the #undef "trick" mentioned elsethread is your
best bet. But contact your sysadmin in any case, and get
him to patch those headers, so nobody else gets burnt.

-Arthur
 
T

Thomas Stegen CES2000

Marc said:
My question was only : is there a special (simple) trick to solve the pb ?

#include <value.h>
#undef MAXINT
#include <param.h>

Maybe, but only maybe.
BTW, have a look at values.h & param.h and you'll see that MAXINT _is_
defined as a macro.

That might be true. I don't have those headers though.
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

Marc Ferry escribió:
Is there a simple trick to avoid this error ?

I noticed that the problem has been fixed on HP-UX 11i. Indeed, values.h
defines MAXINT only if it is not already defined:
#ifndef MAXINT
#define MAXINT ((int)(~(unsigned int)HIBITI))
#endif /** MAXINT **/

Change your values.h in 10.20 to do the same.

Regards.
 
T

tom_usenet

Don't you mix up with comp.std.c++ ?

Nope: http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9
Not yet. I am going to look for my support contract with HP (if I have one).

Thanks for your advice.

Either you're going to have to edit the system headers yourself, or
you're going to have to edit the 3rd party library, or you're going to
have to get a patch from HP to fix the system headers for you. The 3rd
option sounds best to me...

Tom
 
N

Nick Austin

Question: Where should I put these lines ?

In the files that include <values.h> and <param.h>.

If you cannot modify either of these files then the process needs
to be applied recursively; so if <foo.h> contains #include <values.h>
Remember: I cannot change the includes done by the libraries because I
don't own them (external product). And I doubt that both values.h and
param.h includes are in the same library.

This highlights a design issue.

When designing and implementing header files for a third party you
need rules to avoid namespace clashes. If this is not possible an
alternative is to split the application into translation units.
Each translation unit is designed so that it only needs to include
definitions from one set of header files.

Nick.
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top