Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does the standard specify calling conventions?

Reply
Thread Tools

Does the standard specify calling conventions?

 
 
Stuart Redmann
Guest
Posts: n/a
 
      09-13-2010
Hello newsgroup,

does the C++ standard say anything about calling conventions (http://
en.wikipedia.org/wiki/X86_calling_conventions) or is this an
implementation detail?

Thanks in advance,
Stuart
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      09-13-2010
On 09/13/10 07:58 PM, Stuart Redmann wrote:
> Hello newsgroup,
>
> does the C++ standard say anything about calling conventions (http://
> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
> implementation detail?


The latter unfortunately.

--
Ian Collins
 
Reply With Quote
 
 
 
 
BGB / cr88192
Guest
Posts: n/a
 
      09-13-2010

"Stuart Redmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello newsgroup,
>
> does the C++ standard say anything about calling conventions (http://
> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
> implementation detail?
>


technically, it is an implementation detail, as far as any standards are
concerned...

FWIW, that code actually runs on computers is an implementation detail.

however, these calling conventions are generally well accepted, and often
used across language boundaries as well.



 
Reply With Quote
 
Marcel Müller
Guest
Posts: n/a
 
      09-13-2010
Stuart Redmann wrote:
> does the C++ standard say anything about calling conventions (http://
> en.wikipedia.org/wiki/X86_calling_conventions)


No, and it will never. Note that a calling convention that works on
Hardware X may not even exist on Hardware Y, e.g because there are less
registers available or the stack alignment is different.

If you need to rely on calling conventions (most probably for
callbacks), you have to deal with platform specific extensions.


Marcel
 
Reply With Quote
 
Goran Pusic
Guest
Posts: n/a
 
      09-13-2010
On Sep 13, 9:58*am, Stuart Redmann <(E-Mail Removed)> wrote:
> Hello newsgroup,
>
> does the C++ standard say anything about calling conventions (http://
> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
> implementation detail?


The latter. Standard can't possibly specify calling conventions, not
unless it wants to make massive presumptions about the underlying
hardware. Take a look e.g. at i960 CPU (http://en.wikipedia.org/wiki/
Intel_i960#Architecture) and register windows featured by this CPU
(http://en.wikipedia.org/wiki/Register_window). Compiling for this is
wildly different from anything one would want to do on x86. What good
would it be trying to standardize in such a situation? That's why
(among other things) why standard talks about abstract execution
machine or what's it named.

OTOH, calling conventions are hardware- and system- specific, so
system and hardware is what one should be looking at. Tool chains are
in practice obliged to adhere to that, and to the prevailing tool
chain's way of working (e.g. gcc on linux, msc on windows).

Goran.
 
Reply With Quote
 
Stuart Redmann
Guest
Posts: n/a
 
      09-13-2010
On 13 Sep., Stuart Redmann wrote:
> Hello newsgroup,
>
> does the C++ standard say anything about calling conventions (http://
> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
> implementation detail?


Thanks for the quick answer Ian, BGB, Marcel and Goran.
[The answer I received was that the later is the case.]

I stumbled over this when someone in this newsgroup asked about IO
manipulators for his ostream-derived class (see
d1cd356b-9407-481a-8d6c-a5a1151dc534...oglegroups.com). I
posted some code that works under MS Visual C, and would be standard-
conformant WRT calling conventions, but still does work on his
machine:
std:stream& operator<< (std:stream& (__cdecl *_F)
(std:stream&));
cannot be compiled with his version of the STL because it doesn't know
__cdecl.

Am I getting this 100% right: Above definition of IO manipulators is
standard-conformant? Or are IO manipulators not part of the standard?

Thanks,
Stuart
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-13-2010
On 09/13/10 09:07 PM, Stuart Redmann wrote:
> On 13 Sep., Stuart Redmann wrote:
>> Hello newsgroup,
>>
>> does the C++ standard say anything about calling conventions (http://
>> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
>> implementation detail?

>
> Thanks for the quick answer Ian, BGB, Marcel and Goran.
> [The answer I received was that the later is the case.]
>
> I stumbled over this when someone in this newsgroup asked about IO
> manipulators for his ostream-derived class (see
> d1cd356b-9407-481a-8d6c-a5a1151dc534...oglegroups.com). I
> posted some code that works under MS Visual C, and would be standard-
> conformant WRT calling conventions, but still does work on his
> machine:
> std:stream& operator<< (std:stream& (__cdecl *_F)
> (std:stream&));
> cannot be compiled with his version of the STL because it doesn't know
> __cdecl.
>
> Am I getting this 100% right: Above definition of IO manipulators is
> standard-conformant? Or are IO manipulators not part of the standard?


"__cdecl" is a windows thingy, not used elsewhere.

--
Ian Collins
 
Reply With Quote
 
Stuart Redmann
Guest
Posts: n/a
 
      09-13-2010
> On 09/13/10 Stuart Redmann wrote:
> > On 13 Sep., Stuart Redmann wrote:
> >> Hello newsgroup,

>
> >> does the C++ standard say anything about calling conventions (http://
> >> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
> >> implementation detail?

>
> > Thanks for the quick answer Ian, BGB, Marcel and Goran.
> > [The answer I received was that the later is the case.]

>
> > I stumbled over this when someone in this newsgroup asked about IO
> > manipulators for his ostream-derived class (see
> > (E-Mail Removed)). I
> > posted some code that works under MS Visual C, and would be standard-
> > conformant WRT calling conventions, but still does work on his
> > machine:
> > std:stream& *operator<< *(std:stream& *(__cdecl *_F)
> > (std:stream&));
> > cannot be compiled with his version of the STL because it doesn't know
> > __cdecl.

>
> > Am I getting this 100% right: Above definition of IO manipulators is
> > standard-conformant? Or are IO manipulators not part of the standard?



On 13 Sep., Ian Collins wrote:
> "__cdecl" is a windows thingy, not used elsewhere.


Right. But is it standard-compliant? According to
http://www.cplusplus.com/reference/iostream/ostream/operator<</ I
would say no. However, the answers I got this far give me the
impression that the standard does not disallow the usage of calling
convention modifiers. This would mean that above code would be
standard-conformant.

What I actually want is the clarity that the standard disallows above
code (at best with section number and everything) because else I'll
become a LabView programmer (shudder). Or rather join the forces and
become a Ada95 programmer

Thanks,
Stuart
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-13-2010
On 09/13/10 09:25 PM, Stuart Redmann wrote:
>> On 09/13/10 Stuart Redmann wrote:
>>> On 13 Sep., Stuart Redmann wrote:
>>>> Hello newsgroup,

>>
>>>> does the C++ standard say anything about calling conventions (http://
>>>> en.wikipedia.org/wiki/X86_calling_conventions) or is this an
>>>> implementation detail?

>>
>>> Thanks for the quick answer Ian, BGB, Marcel and Goran.
>>> [The answer I received was that the later is the case.]

>>
>>> I stumbled over this when someone in this newsgroup asked about IO
>>> manipulators for his ostream-derived class (see
>>> (E-Mail Removed)). I
>>> posted some code that works under MS Visual C, and would be standard-
>>> conformant WRT calling conventions, but still does work on his
>>> machine:
>>> std:stream& operator<< (std:stream& (__cdecl *_F)
>>> (std:stream&));
>>> cannot be compiled with his version of the STL because it doesn't know
>>> __cdecl.

>>
>>> Am I getting this 100% right: Above definition of IO manipulators is
>>> standard-conformant? Or are IO manipulators not part of the standard?

>
>
> On 13 Sep., Ian Collins wrote:
>> "__cdecl" is a windows thingy, not used elsewhere.

>
> Right. But is it standard-compliant? According to
> http://www.cplusplus.com/reference/iostream/ostream/operator<</ I
> would say no. However, the answers I got this far give me the
> impression that the standard does not disallow the usage of calling
> convention modifiers. This would mean that above code would be
> standard-conformant.


The only calling convention modifier cites in the standard is
extern "C". Anything else is a compiler specific extension.

> What I actually want is the clarity that the standard disallows above
> code (at best with section number and everything) because else I'll
> become a LabView programmer (shudder). Or rather join the forces and
> become a Ada95 programmer


It can't disallow something it knows nothing about. As soon as you
start using compiler specific extensions, your code is no longer
standard C++.

--
Ian Collins
 
Reply With Quote
 
Stuart Redmann
Guest
Posts: n/a
 
      09-13-2010
[snipped original question about calling convention modifiers like
MS's __cdecl in STL code]

On 13 Sep., Ian Collins wrote:
> The only calling convention modifier cites in the standard is
> extern "C". *Anything else is a compiler specific extension.


On 09/13/10 Stuart Redmann wrote:
> > What I actually want is the clarity that the standard disallows above
> > code (at best with section number and everything) because else I'll
> > become a LabView programmer (shudder). Or rather join the forces and
> > become a Ada95 programmer


On 13 Sep., Ian Collins wrote:
> It can't disallow something it knows nothing about. *As soon as you
> start using compiler specific extensions, your code is no longer
> standard C++.


Thanks for the clarification. I guess that this is another item on
MS's list where the product is not standard-conformant.

Thanks,
Stuart
 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
What are the standard network functions provided in standard C? disappearedng@gmail.com C Programming 5 06-10-2008 08:57 PM
when using regex object, does one specify "^" as a modifiier? Jake Barnes Javascript 6 04-09-2006 12:53 PM
add pexpect to the standard library, standard "install" mechanism. funkyj Python 5 01-20-2006 08:35 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM



Advertisments