What code will be executed faster when repeatedly called, will VS2010 optimize anything?
one)
int Function(){ int Var; Var=2*2; return (Var); }
2)
int Function(){ static int Var; Var=2*2; return (Var); }
3)
int Function(){ return (2*2); }
The second question is, what is the most effective dereference or reference to the index !?
The third question is, in the code below, is it possible to optimize something or is it perfect? :)
unsigned long Time2Sec(unsigned char *pbTimeString){ unsigned long dwResult; dwResult=((*pbTimeString-'0')*10+(*(pbTimeString+1)-'0'))*3600+ ((*(pbTimeString+3)-'0')*10+(*(pbTimeString+4)-'0'))*60+ ((*(pbTimeString+6)-'0')*10+(*(pbTimeString+7)-'0')); return (dwResult); }
The fourth question is what works faster (by the condition of the problem - one if statement excludes the other)
4.1)
if (условие_1) ... if (условие_2) ...
4.2)
if (условие_1) ... else if (условие_2) ...
gcc -O3 -S
I don’t understand what can be improved in it. About the "shooting memory." IMHO obvious paranoia. My approach is simple, the one who gave the wrong data to the low level function is to blame . In real life, it is necessary to check the input data at the place of their receipt from outside the program, and not the arguments of the functions. - avp