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:
{code}
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include
#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);
}
{code}
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 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
Vote for best question.
Score: 0
# Vote: 0
Date Posted: 18-Dec-2014, at 12:24 PM EST
From: Marko Majic
Re: BCB XE7 64-bit compiler: Trouble with max() function
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
>
> 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)
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 18-Dec-2014, at 1:30 PM EST
From: Remy Lebeau (TeamB)
Re: BCB XE7 64-bit compiler: Trouble with max() function
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
And that seems to work for both (with or without std::)...
Thanks,
Marko
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 18-Dec-2014, at 12:54 PM EST
From: Marko Majic
Re: BCB XE7 64-bit compiler: Trouble with max() function
Marko wrote:
> So - here's the code:
You are trying to use the C max() macro. Try using the C++ std::max() function
instead:
{code}
#include
....
long c = std::max(a, b);
{code}
--
Remy Lebeau (TeamB)