By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

Where max and min int are defined?

P: n/a
Hi,

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

Best wishes,
Peng

Nov 6 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Pe*******@gmail.com 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.

Nov 6 '05 #2

P: n/a

<Pe*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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
Nov 6 '05 #3

P: n/a

Josh Mcfarlane wrote:
Pe*******@gmail.com 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 '05 #4

P: n/a

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:Yu**************@newsread2.news.pas.earthlink .net...

<Pe*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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
Nov 6 '05 #5

P: n/a
* Pe*******@gmail.com:

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?
Nov 6 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.