Where's max() - Linux

This is a discussion on Where's max() - Linux ; Which header is max() defined in on GNU/Linux ? I cannot seem to find it anywhere. Many thanks in advance, Aaron...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Where's max()

  1. Where's max()

    Which header is max() defined in on GNU/Linux ?

    I cannot seem to find it anywhere.

    Many thanks in advance,

    Aaron



  2. Re: Where's max()

    "Aaron Gray" writes:

    > Which header is max() defined in on GNU/Linux ?
    >
    > I cannot seem to find it anywhere.


    What makes you think it exists?

    --
    Måns Rullgård
    mans@mansr.com

  3. Re: Where's max()

    On 2008-04-28, Aaron Gray wrote:

    > Which header is max() defined in on GNU/Linux ?


    $ grep -r '#[ \t]*define[ \t]*max(' /usr/include
    /usr/include/X11/Xlibint.h:#define max(a,b) (((a) > (b)) ? (a) : (b))
    /usr/include/xorg/misc.h:#define max(a, b) (((a) > (b)) ? (a) : (b))
    /usr/include/cups/driver.h:# define max(a,b) ((a) > (b) ? (a) : (b))
    /usr/include/python2.4/Numeric/f2c.h:#define max(a,b) ((a) >= (b) ? (a) : (b))

    > I cannot seem to find it anywhere.


    It's not in any of the "standard" header files.

    It's pretty trivial to add a line like this to your source code:

    #define max(a,b) (((a) > (b)) ? (a) : (b))

    --
    Grant Edwards grante Yow! The PINK SOCKS were
    at ORIGINALLY from 1952!!
    visi.com But they went to MARS
    around 1953!!

  4. Re: Where's max()

    Grant Edwards writes:

    > On 2008-04-28, Aaron Gray wrote:
    >
    >> Which header is max() defined in on GNU/Linux ?

    >
    > $ grep -r '#[ \t]*define[ \t]*max(' /usr/include
    > /usr/include/X11/Xlibint.h:#define max(a,b) (((a) > (b)) ? (a) : (b))
    > /usr/include/xorg/misc.h:#define max(a, b) (((a) > (b)) ? (a) : (b))
    > /usr/include/cups/driver.h:# define max(a,b) ((a) > (b) ? (a) : (b))
    > /usr/include/python2.4/Numeric/f2c.h:#define max(a,b) ((a) >= (b) ? (a) : (b))
    >
    >> I cannot seem to find it anywhere.

    >
    > It's not in any of the "standard" header files.
    >
    > It's pretty trivial to add a line like this to your source code:
    >
    > #define max(a,b) (((a) > (b)) ? (a) : (b))


    Notice that one of the matches above uses (a) >= (b). While this will
    give the same result as (a) > (b) in simple cases, it changes which of
    the arguments is evaluated twice. Consider this code fragment:

    int a = 0, b = 0;
    int c = max(a++, b++);

    In both cases, the value of c will be 1 (perhaps unexpectedly).
    However, the values of a and b will differ.

    Moral of the story: don't give macros arguments with side-effects.

    --
    Måns Rullgård
    mans@mansr.com

  5. Re: Where's max()

    "Grant Edwards" wrote in message
    news:i8edndday8KCh4vVnZ2dnUVZ_srinZ2d@visi...
    > On 2008-04-28, Aaron Gray wrote:
    >
    >> Which header is max() defined in on GNU/Linux ?

    >
    > $ grep -r '#[ \t]*define[ \t]*max(' /usr/include
    > /usr/include/X11/Xlibint.h:#define max(a,b) (((a) > (b)) ? (a) : (b))
    > /usr/include/xorg/misc.h:#define max(a, b) (((a) > (b)) ? (a) : (b))
    > /usr/include/cups/driver.h:# define max(a,b) ((a) > (b) ? (a) : (b))
    > /usr/include/python2.4/Numeric/f2c.h:#define max(a,b) ((a) >= (b) ? (a) :
    > (b))
    >
    >> I cannot seem to find it anywhere.

    >
    > It's not in any of the "standard" header files.


    Ah, thats why I could not find it !

    > It's pretty trivial to add a line like this to your source code:
    >
    > #define max(a,b) (((a) > (b)) ? (a) : (b))


    Yes, thats what I did as a temporary but now perminent hack.

    Many thanks,

    Aaron



  6. Re: Where's max()

    "Måns Rullgård" wrote in message
    news:yw1xtzhlsu6m.fsf@thrashbarg.mansr.com...
    > "Aaron Gray" writes:
    >
    >> Which header is max() defined in on GNU/Linux ?
    >>
    >> I cannot seem to find it anywhere.

    >
    > What makes you think it exists?


    : )

    Aaron



  7. Re: Where's max()

    Aaron Gray wrote:
    > Which header is max() defined in on GNU/Linux ?


    > I cannot seem to find it anywhere.


    Sorry, but not finding it anywhere already points you in the
    right direction: there's no max() function or macro (in C or
    C++ at least). Moreover, it's not clear what this function
    (or macro?) is supposed to do - should it compare the values
    of two variables of a certain, identical type and return the
    larger one, should it determine the largest value of an array
    or do you want to get the maximum of values of different
    types (i.e. a double and an int etc.)? Or do you have some
    program that uses 'max()' and you can't find where it's
    defined or at least declared? In that case it must be in
    some header file. Invoking gcc with the '-E' option may
    be helpful in that case - the output should tell you what
    max() is - if it's a macro you will get its '#define',
    otherwise its a function declared in one of the included
    header files.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  8. Re: Where's max()

    Jens Thoms Toerring wrote:

    > Sorry, but not finding it anywhere already points you in the
    > right direction: there's no max() function or macro (in C or
    > C++ at least).


    You are wrong, in C++ it does exist and it's included in .


    --
    SF

    Games are very educational. Scrabble teaches us vocabulary, Monopoly teaches
    us cash-flow management, and Dungeons & Dragons teaches us to loot dead bodies.

  9. Re: Where's max()

    Jens Thoms Toerring wrote:

    > Sorry, but not finding it anywhere already points you in the
    > right direction: there's no max() function or macro (in C or
    > C++ at least).


    The STL comes with std::max()

    http://gcc.gnu.org/onlinedocs/libstd...a254382021ccaf

+ Reply to Thread