Re: operator new not forced to throw std::bad_alloc?
On May 13, 8:10 pm, Ian Collins <ian-n...@hotmail.com> wrote:
numerical.simulat...@web.de wrote:.
void* __cdecl operator new(size_t nSize)
That (__cdecl) makes the function non-standard, so all bets are probably
off at this point.
How does a "__cdecl" specifier make the new() function declaration
"non-standard"? The "__cdecl" specifier, after all, is not part of
the function's signature - so its presence should not prevent the
signature of the new() function from matching the signature specified
in the Standard. Or, to put it another way: does the C++ Standard
require that implementations of new() adhere to a particular calling
convention?
The answer is "of course not". The C++ Standard says nothing about
calling conventions - so as far as the Standard is concerned, one
calling convention is as good as another. And, logically, every
function must adhere to some kind of calling conventions, so the only
effect of removing the "__cdecl" specifier would be to make the
calling convention implicitly - instead of explicitly - specified.
Moreover, Visual Studio offers other ways to specify a function's
calling convention. So how could it be OK to specify a function's
calling convention with, say, compiler flags, but not be OK to specify
the exact same settings directly in the source code?
Furthermore, the name "__cdecl" itself does conform to the C++
Standard. Because - according to the Standard - names that begin with
two underscores are reserved to the implementation for "any use."
Presumably, "any use" includes use as function attributes.
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]