Where max and min int are defined?

Discussion in 'C++' started by PengYu.UT@gmail.com, Nov 6, 2005.

  1. Guest

    Hi,

    Would you please let me know where max and min int are defined in C++?

    Best wishes,
    Peng
     
    , Nov 6, 2005
    #1
    1. Advertising

  2. wrote:
    > Hi,
    >
    > Would you please let me know where max and min int are defined in C++?
    >
    > Best wishes,
    > Peng


    I believe it's compiler dependent, as on a certain 32-bit compiler, int
    may be 4 bytes, but on a certain 64-bit compiler, int may be 8 bytes.
     
    Josh Mcfarlane, Nov 6, 2005
    #2
    1. Advertising

  3. Mike Wahler Guest

    <> wrote in message
    news:...
    > Hi,
    >
    > Would you please let me know where max and min int are defined in C++?


    They are *declared* by the standard header <algorithm>.
    Where they are *defined* is implementation-dependent.
    (Although in all cases I've seen, the definitions themselves
    are in the header, so serve as the declarations)

    A good C++ book can answer this type of question. IMO
    the best one specifically about the standard library
    is: www.josuttis.com/libbook


    -Mike
     
    Mike Wahler, Nov 6, 2005
    #3
  4. Guest

    Josh Mcfarlane wrote:
    > wrote:
    > > Hi,
    > >
    > > Would you please let me know where max and min int are defined in C++?
    > >
    > > Best wishes,
    > > Peng

    >
    > I believe it's compiler dependent, as on a certain 32-bit compiler, int
    > may be 4 bytes, but on a certain 64-bit compiler, int may be 8 bytes.


    Do you mean platform dependent? Do you know where MAX_INT and MIN_INT
    are defined in GCC?
     
    , Nov 6, 2005
    #4
  5. Mike Wahler Guest

    "Mike Wahler" <> wrote in message
    news:Yuubf.678$...
    >
    > <> wrote in message
    > news:...
    >> Hi,
    >>
    >> Would you please let me know where max and min int are defined in C++?

    >
    > They are *declared* by the standard header <algorithm>.
    > Where they are *defined* is implementation-dependent.
    > (Although in all cases I've seen, the definitions themselves
    > are in the header, so serve as the declarations)
    >
    > A good C++ book can answer this type of question. IMO
    > the best one specifically about the standard library
    > is: www.josuttis.com/libbook


    After reading another reply, I see I may have misunderstood
    you. I thought you were asking about the functions 'min()'
    and 'max()'.

    There are two places where the (implementation-define)
    minimum and maximum values for type 'int' are found:

    1) The values returned by functions:
    std::numeric_limits<int>::min()
    std::numeric_limits<int>::max()
    (these are declared by header <limits>

    2) The values of the macros INT_MIN and INT_MAX,
    declared by header <limits.h> or <climits>

    -Mike
     
    Mike Wahler, Nov 6, 2005
    #5
  6. * :
    >
    > Would you please let me know where max and min int are defined in C++?


    If you're asking for maximum and minimum values of 'int' type, then you
    have a choice of INT_MIN and INT_MAX constants from <climits>, or
    std::numeric_limits<int>::min() and std::numeric_limits<int>::max()
    functions from <limits>. The latter can be used in template code.

    If you're asking for function to compute min and max of two 'int'
    values, then that's std::min() and std::max() from <algorithm>.


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 6, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lois
    Replies:
    1
    Views:
    3,419
    Ryan Stewart
    Dec 27, 2004
  2. Schnoffos
    Replies:
    2
    Views:
    1,260
    Martien Verbruggen
    Jun 27, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,719
    Old Wolf
    Jan 20, 2004
  4. juergen
    Replies:
    3
    Views:
    585
    opalinski from opalpaweb
    Sep 20, 2006
  5. carmen

    Converting hrs and min to just min

    carmen, Aug 10, 2004, in forum: ASP General
    Replies:
    4
    Views:
    157
    carmen
    Aug 10, 2004
Loading...

Share This Page