Why is MAXINT doubly defined in system include files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Ferry

    Why is MAXINT doubly defined in system include files

    I already posted this mail in comp.sys.hp and comp.sys.hp.hpu x 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)(~(unsign ed int)HIBITI))
    #endif /** MAXINT **/

    Thanks for your advice.
    Marc Ferry

  • tom_usenet

    #2
    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.c om> wrote:
    [color=blue]
    >I already posted this mail in comp.sys.hp and comp.sys.hp.hpu x 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.progr ammer 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

    Comment

    • Nick Austin

      #3
      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.c om> 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.

      Comment

      • Marc Ferry

        #4
        Re: Why is MAXINT doubly defined in system include files

        Nick Austin wrote:
        [color=blue]
        > <mferry.ext@rd. francetelecom.c om> 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.

        Comment

        • Marc Ferry

          #5
          Re: Why is MAXINT doubly defined in system include files

          tom_usenet wrote:
          [color=blue]
          > <mferry.ext@rd. francetelecom.c om> wrote:
          >[color=green]
          >>I already posted this mail in comp.sys.hp and comp.sys.hp.hpu x 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.progr ammer 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

          Comment

          • Joona I Palaste

            #6
            Re: Why is MAXINT doubly defined in system include files

            Marc Ferry <mferry.ext@rd. francetelecom.c om> scribbled the following
            on comp.lang.c:[color=blue]
            > tom_usenet wrote:[color=green]
            >> <mferry.ext@rd. francetelecom.c om> wrote:
            >>[color=darkred]
            >>>I already posted this mail in comp.sys.hp and comp.sys.hp.hpu x 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.progr ammer 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.hel sinki.fi) ------------- Finland --------\
            \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
            "Make money fast! Don't feed it!"
            - Anon

            Comment

            • Alex

              #7
              Re: Why is MAXINT doubly defined in system include files

              "Marc Ferry" <mferry.ext@rd. francetelecom.c om> wrote in message
              news:bme8u7$jor 3@news.rd.franc etelecom.fr...[color=blue]
              > Nick Austin wrote:[color=green]
              > > <mferry.ext@rd. francetelecom.c om> 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


              Comment

              • Arthur J. O'Dwyer

                #8
                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)(~(unsign ed 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

                Comment

                • Thomas Stegen CES2000

                  #9
                  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

                  Comment

                  • Julián Albo

                    #10
                    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)(~(unsign ed int)HIBITI))
                    > #endif /** MAXINT **/[/color]

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

                    Regards.

                    Comment

                    • tom_usenet

                      #11
                      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.c om> wrote:
                      [color=blue]
                      >tom_usenet wrote:
                      >[color=green]
                      >> <mferry.ext@rd. francetelecom.c om> wrote:
                      >>[color=darkred]
                      >>>I already posted this mail in comp.sys.hp and comp.sys.hp.hpu x 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.progr ammer 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

                      Comment

                      • Nick Austin

                        #12
                        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.c om> wrote:
                        [color=blue]
                        >Nick Austin wrote:
                        >[color=green]
                        >> <mferry.ext@rd. francetelecom.c om> 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.

                        Comment

                        Working...