public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Where should g++ find a 'max' macro or function ?
@ 2003-11-10 12:17 Michael Svetlik
  2003-11-10 12:53 ` Eljay Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Svetlik @ 2003-11-10 12:17 UTC (permalink / raw)
  To: gcc-help

Hi, folks.

I'm sure, somewhere in a mailing list archive around the globe is the answer - 
I'm too blockheaded to find it.

The problem: a little file
/* -------------------------------------------------------- */
int maxxx (int a, int b) {
	return max(a,b);
}
/* -------------------------------------------------------- */
is pushed into g++ for compilation :
>> g++ -o max.o -c max.c
and produces :
max.c: In function `int maxxx(int, int)':
max.c:4: `max' undeclared (first use this function)
max.c:4: (Each undeclared identifier (bla blaaa ....)

g++ is
>>Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/specs
Configured with: /home/michl/sources/gnu/gcc-3.2.3/configure 
--enable-languages=c,c++
Thread model: posix
gcc version 3.2.3

The output of
>> g++ -E max.c
is 
<output>
# 1 "max.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "max.c"

int maxxx (int a, int b) {

        return max(a,b);



}
</output>

Strange, g++-2.95.3 is capable of translating it correctly, but doesn't 
produce the 'built-in' stuff with '-E'.

I've checked Stroustrup, as well as the archive here, without success. Anyone 
there, who has an idea ?

TIA
Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where should g++ find a 'max' macro or function ?
  2003-11-10 12:17 Where should g++ find a 'max' macro or function ? Michael Svetlik
@ 2003-11-10 12:53 ` Eljay Love-Jensen
  2003-11-10 18:31   ` Michael Svetlik
  0 siblings, 1 reply; 4+ messages in thread
From: Eljay Love-Jensen @ 2003-11-10 12:53 UTC (permalink / raw)
  To: Michael Svetlik, gcc-help

Hi Michael,

In C++ (and in C) it's strongly recommended that you include the proper header file that declares the symbols utilized.

Try this in your little program:
/* -------------------------------------------------------- */
#include <algorithm>
    using std::max;

int maxxx(int a, int b)
{
    return max(a,b);
}
/* -------------------------------------------------------- */

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where should g++ find a 'max' macro or function ?
  2003-11-10 12:53 ` Eljay Love-Jensen
@ 2003-11-10 18:31   ` Michael Svetlik
  2003-11-11 13:19     ` Eljay Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Svetlik @ 2003-11-10 18:31 UTC (permalink / raw)
  To: Eljay Love-Jensen, gcc-help

On Monday 10 November 2003 13:54, Eljay Love-Jensen wrote:
>
> In C++ (and in C) it's strongly recommended that you include the proper
> header file that declares the symbols utilized.
>
> Try this in your little program:
> /* -------------------------------------------------------- */
> #include <algorithm>
>     using std::max;

Thanks, helped.

I already knew about strict prototyping, but didn't know _WHERE_ to find the 
prototype. To avoid messing up the gcc-help list next time, could you - or 
anyone of the guru's - point me a document, specifying where to find such 
standard utilities, means which stl header to include ? Would be great ...

Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where should g++ find a 'max' macro or function ?
  2003-11-10 18:31   ` Michael Svetlik
@ 2003-11-11 13:19     ` Eljay Love-Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2003-11-11 13:19 UTC (permalink / raw)
  To: Michael Svetlik, gcc-help

Hi Michael,

I usually look in the C++ header files themselves.  Note:  some compilers (*cough* Microsoft *cough) are not ISO 14882 compliant/up-to-date, and may put the symbols in the incorrect header file (if not missing the sanctioned symbol entirely)... so some caution is warranted.

Or I refer to "The C++ Programming Language" (3rd ed, or special ed) by Bjarne Stroustrup.

If you are a glutton for punishment, the ISO 14882 specification is the gospel.  But it's not light reading.  Cures insomnia, though.

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-11 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-10 12:17 Where should g++ find a 'max' macro or function ? Michael Svetlik
2003-11-10 12:53 ` Eljay Love-Jensen
2003-11-10 18:31   ` Michael Svetlik
2003-11-11 13:19     ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).