Sign in to follow this  
The C modest god

Constantsd in C++

Recommended Posts

It instantiates (sp) int arg with the number 10.

Or rather, it "copies" 10 in arg:

arg(10)

If you were to put 10 in a variable and pass that to the function it would do something like this:

int temp = 10;
arg(temp)

So it basicly creates a temporary variable.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
Does he keep a place on the stack and put 10 in it?


The behaviour is implementation-defined. The language only guarantees that arg will be a local variable with an initial value of 10.

Share this post


Link to post
Share on other sites
Quote:
But where it creates this temporary variable? In the stack?
Probably. If the function being called expects to find its parameters on the stack, then that is where the argument will be placed. If the function accepts its parameters in registers, the constant will be placed in the necessary register.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by The C modest god
Does he keep a place on the stack and put 10 in it?


The behaviour is implementation-defined. The language only guarantees that arg will be a local variable with an initial value of 10.


And that's about all you can reasonably assume, too, without more information. In "Real Life" (tm) this depends on:

0) Whatever your compiler spits out. Duh. But seriously, look at the disassembly* if you really need to know (you don't).
1) Wheither or not it's inlined. In TCMG's brain dead simple case, anything that can reasonably call itself a compiler won't even call it at all - recognized by the optimizer as a no-op. In the more general case, if inlined, the exact placement will depend on the code that preceeds the call to the funciton, most likely. The number of variables at work here may exceed atoms in the universe.
2) Compiler, environment, phase of the moon.
3) Calling convention, assuming Venus is properly aligned with Mars, you're driving a hybrid on a Thursday, and you're a virgin Virgo. Some (non-standard) keywords to google: __fastcall, __stdcall, __thiscall, and __cdecl (?)

* OF RELEASE MODE OR I WILL STAB YOU

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this