Where max and min int are defined?

P

PengYu.UT

Hi,

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

Best wishes,
Peng
 
J

Josh Mcfarlane

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.
 
M

Mike Wahler

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
 
P

PengYu.UT

Josh said:
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?
 
M

Mike Wahler

Mike Wahler said:
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
 
A

Alf P. Steinbach

* (e-mail address removed):
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>.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top