Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: BCB XE7 64-bit compiler: Trouble with max() function


This question is answered.


Permlink Replies: 4 - Last Post: Dec 18, 2014 1:32 PM Last Post By: Marko Majic
Marko Majic

Posts: 14
Registered: 1/20/03
BCB XE7 64-bit compiler: Trouble with max() function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2014 12:24 PM
This is probably something rather simple (I mean, it certainly IS beyond basic!) but it has baffled me for the past 45 minutes so I thought I'd post a question here in hopes someone might have an answer off the top of their head...

So - here's the code:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdlib.h>
#include "TestMainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
	long a = 3, b = 5;
	long c = max(a, b);
}
 


It doesn't get much simpler than that... The code compiles fine as a 32-bit target (and, in all honesty, it compiles fine even without #include <stdlib.h> with 32-bit compiler!). However, trying to compile it with a 64-bit compiler generates an error:

[bcc64 Error] TestMainForm.cpp(49): use of undeclared identifier 'max'

Can't quite figure out why, though... Anyone?

Thanks,

Marko
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: BCB XE7 64-bit compiler: Trouble with max() function
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2014 12:40 PM   in response to: Marko Majic in response to: Marko Majic
Marko wrote:

So - here's the code:

You are trying to use the C max() macro. Try using the C++ std::max() function
instead:

#include <algorithm> 
...
long c = std::max(a, b);


--
Remy Lebeau (TeamB)
Marko Majic

Posts: 14
Registered: 1/20/03
Re: BCB XE7 64-bit compiler: Trouble with max() function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2014 12:54 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy,

Yeah, that was the first thing I tried, but got:

[bcc64 Error] TestMainForm.cpp(49): no member named 'max' in namespace 'std'

with a 64-bit compiler (and, once again, no complaints from the 32-bit compiler)...

Then (just now), thought I'd try:

#include <algorithm>

And that seems to work for both (with or without std::)...

Thanks,

Marko
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: BCB XE7 64-bit compiler: Trouble with max() function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2014 1:27 PM   in response to: Marko Majic in response to: Marko Majic
Marko wrote:

Yeah, that was the first thing I tried, but got:

[bcc64 Error] TestMainForm.cpp(49): no member named 'max' in namespace
'std'

with a 64-bit compiler (and, once again, no complaints from the 32-bit
compiler)...

Then you did not include the proper header for it.

Then (just now), thought I'd try:

#include <algorithm>

And that seems to work for both

I did tell you to use that #include. std::max() is an actual function, not a macro.

with or without std::

The 'std::' is required, unless you have a 'using namespace std' or 'using std::max' statement in your code. If it is working in 32bit without 'std::' and either 'using'' statement, then you are still calling the C macro, not the C++ function. They are NOT the same thing!

--
Remy Lebeau (TeamB)
Marko Majic

Posts: 14
Registered: 1/20/03
Re: BCB XE7 64-bit compiler: Trouble with max() function  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2014 1:32 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Yes, I intended to mark your answer as correct... I think I did it now...

Marko
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02