Connecting Tech Pros Worldwide Help | Site Map

Why is MAXINT doubly defined in system include files

Marc Ferry
Guest
 
Posts: n/a
#1: Jul 19 '05
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

tom_usenet
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


On Mon, 13 Oct 2003 13:53:07 +0200, Marc Ferry
<mferry.ext@rd.francetelecom.com> wrote:
[color=blue]
>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.[/color]

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.
[color=blue]
>*************************
>
>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[/color]

MAXINT isn't a standard macro, the standard macro is INT_MAX, from
<limits.h>.
[color=blue]
>Why is that so ?[/color]

Presumably a bug. Have you asked HP?

Tom
Nick Austin
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


On Mon, 13 Oct 2003 13:53:07 +0200, Marc Ferry
<mferry.ext@rd.francetelecom.com> wrote:
[color=blue]
>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[/color]

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

Nick.

Marc Ferry
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


Nick Austin wrote:
[color=blue]
> <mferry.ext@rd.francetelecom.com> wrote:
>[color=green]
>>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[/color]
>
> #include <values.h>
> #undef MAXINT
> #include <sys/param.h>[/color]

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.

Marc Ferry
Guest
 
Posts: n/a
#5: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


tom_usenet wrote:
[color=blue]
> <mferry.ext@rd.francetelecom.com> wrote:
>[color=green]
>>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.[/color]
>
> 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.[/color]

Don't you mix up with comp.std.c++ ?
[color=blue][color=green]
>>*************************
>>
>>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[/color]
>
>
> MAXINT isn't a standard macro, the standard macro is INT_MAX, from
> <limits.h>.[/color]

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.
[color=blue][color=green]
>>Why is that so ?[/color]
>
> Presumably a bug. Have you asked HP?[/color]

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

Thanks for your advice.
Marc

Joona I Palaste
Guest
 
Posts: n/a
#6: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


Marc Ferry <mferry.ext@rd.francetelecom.com> scribbled the following
on comp.lang.c:[color=blue]
> tom_usenet wrote:[color=green]
>> <mferry.ext@rd.francetelecom.com> wrote:
>>[color=darkred]
>>>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.[/color]
>>
>> 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.[/color][/color]
[color=blue]
> Don't you mix up with comp.std.c++ ?[/color]

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?"

--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Make money fast! Don't feed it!"
- Anon
Alex
Guest
 
Posts: n/a
#7: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


"Marc Ferry" <mferry.ext@rd.francetelecom.com> wrote in message
news:bme8u7$jor3@news.rd.francetelecom.fr...[color=blue]
> Nick Austin wrote:[color=green]
> > <mferry.ext@rd.francetelecom.com> wrote:[color=darkred]
> >>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[/color]
> >
> > #include <values.h>
> > #undef MAXINT
> > #include <sys/param.h>[/color]
>
> Question: Where should I put these lines ?[/color]

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

Alex


Arthur J. O'Dwyer
Guest
 
Posts: n/a
#8: Jul 19 '05

re: Why is MAXINT doubly defined in system include files



On Mon, 13 Oct 2003, Marc Ferry wrote:[color=blue]
>
> 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[/color]


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.

[color=blue]
> 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 **/[/color]

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
Thomas Stegen CES2000
Guest
 
Posts: n/a
#9: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


Marc Ferry wrote:
[color=blue]
> My question was only : is there a special (simple) trick to solve the pb ?[/color]

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

Maybe, but only maybe.
[color=blue]
>
> BTW, have a look at values.h & param.h and you'll see that MAXINT _is_
> defined as a macro.[/color]

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

--
Thomas

Julián Albo
Guest
 
Posts: n/a
#10: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


Marc Ferry escribió:
[color=blue]
> 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 **/[/color]

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

Regards.
tom_usenet
Guest
 
Posts: n/a
#11: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


On Mon, 13 Oct 2003 15:26:05 +0200, Marc Ferry
<mferry.ext@rd.francetelecom.com> wrote:
[color=blue]
>tom_usenet wrote:
>[color=green]
>> <mferry.ext@rd.francetelecom.com> wrote:
>>[color=darkred]
>>>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.[/color]
>>
>> 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.[/color]
>
>Don't you mix up with comp.std.c++ ?[/color]

Nope: http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
[color=blue][color=green]
>> Presumably a bug. Have you asked HP?[/color]
>
>Not yet. I am going to look for my support contract with HP (if I have one).
>
>Thanks for your advice.[/color]

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
Nick Austin
Guest
 
Posts: n/a
#12: Jul 19 '05

re: Why is MAXINT doubly defined in system include files


On Mon, 13 Oct 2003 15:22:14 +0200, Marc Ferry
<mferry.ext@rd.francetelecom.com> wrote:
[color=blue]
>Nick Austin wrote:
>[color=green]
>> <mferry.ext@rd.francetelecom.com> wrote:
>>[color=darkred]
>>>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[/color]
>>
>> #include <values.h>
>> #undef MAXINT
>> #include <sys/param.h>[/color]
>
>Question: Where should I put these lines ?[/color]

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>
then find the file that contains #include <foo.h> and include the
#undef there.
[color=blue]
>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.[/color]

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.

Closed Thread