Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > min/max in stdlib.h?!

Reply
Thread Tools

min/max in stdlib.h?!

 
 
copx
Guest
Posts: n/a
 
      01-05-2008
Are the macros min() and max() part of stdlib.h or not? (according to the
standard?)

I have the following problem: I defined my own min() / max() macros because
my compiler (MinGW) does NOT define them. When I tried to compile my program
with lcc-win32 the compiler complained about macro redefinition, because
min() and max() are defined in lcc's stdlib.h..

So do these macros belong there or not?



 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-05-2008
copx wrote:
> Are the macros min() and max() part of stdlib.h or not? (according to the
> standard?)
>
> I have the following problem: I defined my own min() / max() macros because
> my compiler (MinGW) does NOT define them. When I tried to compile my program
> with lcc-win32 the compiler complained about macro redefinition, because
> min() and max() are defined in lcc's stdlib.h..
>
> So do these macros belong there or not?
>

No.

Did you invoke the compiler in conforming mode?

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-05-2008
copx said:

> Are the macros min() and max() part of stdlib.h or not? (according to the
> standard?)


No.

> I have the following problem: I defined my own min() / max() macros
> because my compiler (MinGW) does NOT define them. When I tried to compile
> my program with lcc-win32 the compiler complained about macro
> redefinition, because min() and max() are defined in lcc's stdlib.h..
>
> So do these macros belong there or not?


No, they don't. If they are nevertheless placed there by the
implementation, check that you are invoking the implementation in
conforming mode. If so, then you have uncovered a bug in the
implementation.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-05-2008
copx wrote:
> Are the macros min() and max() part of stdlib.h or not? (according to the
> standard?)
>
> I have the following problem: I defined my own min() / max() macros because
> my compiler (MinGW) does NOT define them. When I tried to compile my program
> with lcc-win32 the compiler complained about macro redefinition, because
> min() and max() are defined in lcc's stdlib.h..
>
> So do these macros belong there or not?
>
>
>


They are not in the standard.
Note that the definition in stdlib.h is:

#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif

If you define those macros before including stdlib.h
yours will be taken. Besides, the compiler just
emits a warning.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-05-2008
P.S.
Please do the same:
#ifndef max
#define ... // your definition
#endif

This will work in lcc and mingw

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-05-2008
jacob navia wrote:
> copx wrote:
>> Are the macros min() and max() part of stdlib.h or not? (according to
>> the standard?)
>>
>> I have the following problem: I defined my own min() / max() macros
>> because my compiler (MinGW) does NOT define them. When I tried to
>> compile my program with lcc-win32 the compiler complained about macro
>> redefinition, because min() and max() are defined in lcc's stdlib.h..
>>
>> So do these macros belong there or not?
>>
>>
>>

>
> They are not in the standard.
> Note that the definition in stdlib.h is:
>
> #ifndef max
> #define max(a,b) (((a) > (b)) ? (a) : (b))
> #define min(a,b) (((a) < (b)) ? (a) : (b))
> #endif
>
> If you define those macros before including stdlib.h
> yours will be taken. Besides, the compiler just
> emits a warning.
>

Do they go away in conforming mode? If not, they should.

You can't expect punters to mess about with the order of macro
definitions and header inclusions. Or do you expect them to ignore
warnings?

--
Ian Collins.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-05-2008
Ian Collins wrote:
> jacob navia wrote:
>> copx wrote:
>>> Are the macros min() and max() part of stdlib.h or not? (according to
>>> the standard?)
>>>
>>> I have the following problem: I defined my own min() / max() macros
>>> because my compiler (MinGW) does NOT define them. When I tried to
>>> compile my program with lcc-win32 the compiler complained about macro
>>> redefinition, because min() and max() are defined in lcc's stdlib.h..
>>>
>>> So do these macros belong there or not?
>>>
>>>
>>>

>> They are not in the standard.
>> Note that the definition in stdlib.h is:
>>
>> #ifndef max
>> #define max(a,b) (((a) > (b)) ? (a) : (b))
>> #define min(a,b) (((a) < (b)) ? (a) : (b))
>> #endif
>>
>> If you define those macros before including stdlib.h
>> yours will be taken. Besides, the compiler just
>> emits a warning.
>>

> Do they go away in conforming mode? If not, they should.
>
> You can't expect punters to mess about with the order of macro
> definitions and header inclusions. Or do you expect them to ignore
> warnings?
>


They go away in conforming mode *now* ...



Will be in the next release

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
copx
Guest
Posts: n/a
 
      01-05-2008

"Ian Collins" <ian-> schrieb im Newsbeitrag
news:...
> copx wrote:
>> Are the macros min() and max() part of stdlib.h or not? (according to the
>> standard?)
>>
>> I have the following problem: I defined my own min() / max() macros
>> because
>> my compiler (MinGW) does NOT define them. When I tried to compile my
>> program
>> with lcc-win32 the compiler complained about macro redefinition, because
>> min() and max() are defined in lcc's stdlib.h..
>>
>> So do these macros belong there or not?
>>

> No.


Ok, thanks.

> Did you invoke the compiler in conforming mode?


Yes, it did.


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-05-2008
copx said:

> "Ian Collins" <ian-> schrieb im Newsbeitrag
> news:...
>
>> Did you invoke the compiler in conforming mode?

>
> Yes, it did.


If you invoked the implementation in its conforming mode and it defined min
and max in stdlib.h, it doesn't really *have* a conforming mode.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      01-05-2008
jacob navia wrote, On 05/01/08 10:30:

<snip min/max being defined in stdlib.h even in conforming mode>

> They go away in conforming mode *now* ...
>
>
>
> Will be in the next release


Perhaps rather that fixing these things one at a time when people
complain you should review all of your standard headers and make sure
than in conforming mode they define what the standard requires and
nothing more (at least, nothing more that is not in your namespace as
implementer, you can still define __ya_bo_sucks_to_you if you want).
--
Flash Gordon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57