Josh @ Dreamland
|
|
Reply #15 Posted on: June 15, 2010, 10:59:27 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Eh, char* and char*& are two different things. Array != &Array... &Array will, should the array for some reason be given a register despite its use, dump the pointer into the memory and give you a reference to it. Assuming you meant Array == Array&, that isn't true, either. If you never state Array = something; in the code taking Array&, it will modify the array without requiring return. Taking Array as a parameter would simply copy the pointer, and only the local copy in the new scope would be changed. Now, in the context of his code, GCC will probably be nice and make it such that (int Array) is the same as (int &Array). So fine. ...But they're still different.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #17 Posted on: June 15, 2010, 03:36:35 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Sure, but good luck passing the array to a function and keeping that true.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
MahFreenAmeh
|
|
Reply #18 Posted on: June 15, 2010, 05:42:57 pm |
|
|
sysadmin
"Web Team" Location: Austin, TX Joined: Apr 2008
Posts: 13
|
DERP
|
|
|
Logged
|
sys(tem)admin(istrator) [java,c++,c,javascript,html,css,php,perl,ruby,python,sql] if you've got ideas, let me hear them.
|
|
|
|
Josh @ Dreamland
|
|
Reply #20 Posted on: June 15, 2010, 10:28:48 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Sorry, but outside of the scope in which it is declared, postfix [] and prefix * are synonymous. #include <stdio.h> int array[3] = { 1, 2, 3 }; void function(int arg[]) { puts((void*)arg == (void*)&arg ? "true" : "fail"); } int main() { return function(array), 0; } fail
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #23 Posted on: June 27, 2010, 09:27:58 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Doesn't seem to have?
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
The 11th plague of Egypt
|
|
Reply #25 Posted on: September 04, 2010, 04:08:46 pm |
|
|
Joined: Dec 2009
Posts: 274
|
A little tip. Instead of
int i; for(i=0; i < width; i++) you could declare you variable at the start of the cycle, like this
for(int i=0; i < width; i++) Also, you can do a lot of cool things, like
for(int i=0, j=5; i < width; i++, j--) It's called comma operator, and it lets you do more in less space.
Moreover, some people suggest ++i instead of i++. Does the same thing, but is more efficient, and is safer for recursive functions.
|
|
« Last Edit: September 04, 2010, 04:11:16 pm by The 11th plague of Egypt »
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #26 Posted on: September 05, 2010, 09:55:16 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Moreover, some people suggest ++i instead of i++. Does the same thing, but is more efficient, and is safer for recursive functions. I'm getting a bit tired of that myth. int i = 0; cout << i++ << endl; cout << ++i << endl; The above prints 0 2. If we were to look at the micro operations, i++ would send to RAM, then increment; ++i would increment, then send to RAM. I.e., the same process, but with the order changed. Neither is more efficient. I've never heard that one is safer than the other for recursive functions. It's a matter of understanding which one will behave in the best manner for the current algorithm.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #28 Posted on: September 05, 2010, 09:00:09 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
-sigh- Yes, I suppose if you take all optimizations away, and are using a non-scalar object, then yes, a pre-increment is more efficient.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|