Click here to Skip to main content
16,011,757 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 22:35
CodingLover17-Dec-07 22:35 
GeneralRe: Number of characters of a string Pin
Maxwell Chen17-Dec-07 22:36
Maxwell Chen17-Dec-07 22:36 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 23:01
CodingLover17-Dec-07 23:01 
JokeRe: Number of characters of a string Pin
CPallini17-Dec-07 23:12
mveCPallini17-Dec-07 23:12 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 23:31
CodingLover17-Dec-07 23:31 
GeneralRe: Number of characters of a string Pin
cp987617-Dec-07 23:37
cp987617-Dec-07 23:37 
GeneralRe: Number of characters of a string Pin
CPallini18-Dec-07 0:04
mveCPallini18-Dec-07 0:04 
GeneralRe: Number of characters of a string Pin
cp987618-Dec-07 0:15
cp987618-Dec-07 0:15 
You are right, for a few cases the difference may be negligible.

My understanding is that the switch statement can be optimized to O(log(N)) operations (using a tree type of search), whereas the simple cascaded if's will be O(N) operations. Obviously these could be the same but the compiler knows it can optimize a switch statement as the cases are all integer constants. I'd be interested to know the results if anyone can be bothered to do some test cases and analyse the code. It may be that the way the case statements are tested using less than operations is indicative that it would use a tree search for more cases (instead of the simple comparisons in the if construct).

Typically for lexical analyzers there are many cases and this type of optimization can be important (even better to use the provided character classification functions like isspace())
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

GeneralRe: Number of characters of a string Pin
CPallini18-Dec-07 0:43
mveCPallini18-Dec-07 0:43 
GeneralRe: Number of characters of a string Pin
cp987618-Dec-07 10:07
cp987618-Dec-07 10:07 
GeneralYou're right Pin
CPallini18-Dec-07 12:33
mveCPallini18-Dec-07 12:33 
GeneralRe: Number of characters of a string Pin
CodingLover18-Dec-07 0:18
CodingLover18-Dec-07 0:18 
GeneralRe: Number of characters of a string Pin
Maxwell Chen18-Dec-07 1:16
Maxwell Chen18-Dec-07 1:16 
QuestionRe: Number of characters of a string Pin
David Crow18-Dec-07 3:20
David Crow18-Dec-07 3:20 
GeneralRe: Number of characters of a string Pin
David Crow18-Dec-07 3:30
David Crow18-Dec-07 3:30 
GeneralRe: Number of characters of a string Pin
jhwurmbach18-Dec-07 4:05
jhwurmbach18-Dec-07 4:05 
GeneralRe: Number of characters of a string Pin
David Crow18-Dec-07 4:14
David Crow18-Dec-07 4:14 
GeneralRe: Number of characters of a string Pin
jhwurmbach18-Dec-07 4:29
jhwurmbach18-Dec-07 4:29 
QuestionHow to read only the integer value of a txt file in C++ Pin
Cabomba17-Dec-07 20:20
Cabomba17-Dec-07 20:20 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Peter Weyzen17-Dec-07 20:48
Peter Weyzen17-Dec-07 20:48 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Cabomba17-Dec-07 21:36
Cabomba17-Dec-07 21:36 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Iain Clarke, Warrior Programmer17-Dec-07 23:48
Iain Clarke, Warrior Programmer17-Dec-07 23:48 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Cabomba18-Dec-07 19:50
Cabomba18-Dec-07 19:50 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Iain Clarke, Warrior Programmer18-Dec-07 23:56
Iain Clarke, Warrior Programmer18-Dec-07 23:56 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Cabomba20-Dec-07 3:51
Cabomba20-Dec-07 3:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.