Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 10, 2013, 08:28 AM   #26
ghellquist
macrumors regular
 
Join Date: Aug 2011
Location: Stockholm Sweden
Quote:
Originally Posted by Sander View Post
It has no obligation to, as the register keyword is "just a hint" (which is actually commonly ignored). In fact, the other way around is also true: The compiler may well decide to keep something in a register when the optimizer thinks that's a good idea, even if you didn't mention the register keyword.
Quite true.

A compiler might even select to not implement a variable at all, depending on optimization. The only thing the compiler promises is to make the code behave as if there was a variable. One exemple is loop optimization, where for example

for (i =1; i++; i<5) { ... do something .. }
might be unfolded inte a number of ... do something ...

as long as the code gives exactly the same result.

// Gunnar
ghellquist is offline   0 Reply With Quote
Old Jan 10, 2013, 12:54 PM   #27
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
In fact, I recall some years ago reading that arguments were being passed in subroutines via registers instead of the stack, as much as possible, because the PPC had a large register file, why waste it?
__________________
You got to be a spirit. You can't be no ghost.
Sydde is offline   0 Reply With Quote
Old Jan 10, 2013, 01:59 PM   #28
jon3543
macrumors 6502
 
Join Date: Sep 2010
The "register" keyword has been effectively deprecated in decent mainstream compilers since the late 80s or thereabouts. By that time, compiler optimization had been implemented such that the compiler could do a better job of register allocation than the user could guide with the register keyword, which has been nothing more than an historical oddity for a very, very long time. It is typical for "register" to be completely ignored, and seeing it in code written in the last couple of decades should cause both eyebrows to raise, because it indicates either (a) something strange is going on and register is not being ignored, or (b) the programmer doesn't know what he's doing.

As for passing function arguments in registers, that is implementation-defined behavior. Usually, there are a number of "calling conventions" that define how arguments are passed, and when passed on the stack, the order in which they're pushed. In general, there can be more arguments than registers, and the stack will be a fallback mechanism even in register-based calling conventions. When the stack is used, there's also the question of who cleans it up, the caller or callee, and that too is defined by the calling convention.

The register keyword is genuine trivia, and calling conventions are something the application programmer can usually ignore. However, the latter can still be important mainly when interfacing with code written in different languages or more generally, code that uses different calling conventions than is the default for the current compiler.
jon3543 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Java confusion DianeK Mac Basics and Help 2 Jun 21, 2013 09:47 PM
Hotspot Confusion skysailing iPhone 5 Dec 23, 2012 09:38 PM
Two monitor confusion kenglade Mac Basics and Help 6 Dec 12, 2012 09:39 AM
10.7 and 10.8 confusion 2056 OS X 5 Dec 9, 2012 01:48 AM
Total Confusion mntr iPhone 2 Nov 29, 2012 12:28 AM

Forum Jump

All times are GMT -5. The time now is 02:08 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC