2 questions

Started by
2 comments, last by Crispy 21 years, 5 months ago
Hi, 1) can a program be optimized by choosing the order in which arguments are passed to a function - since the order in which programs written in different languages pop the arguments from the stack, can be different, there should be symbolic gain if the arguments are organized to fit the code in the function. Right? 2) does C++ have built-in standard exception (div by zero, out of mem, etc) handlers that can be caught without explicitly throwing them? std::xxx handlers don''t seem to be catching excptions that can normally be caught with the general catch(...) statement. Thanks, Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
Don''t know about #2, but #1 is easy. Functions don''t actually pop the parameters off the stack. They are accessed directly, through the base pointer. So changing the order shouldn''t make any difference (unless in extreme cases where there might be some caching issues, but you''d have to work hard to achieve that).

Kippesoep
1) you won''t gain anything, unless you''re passing huge arrays by value or something similarly unusual. you can choose between first-to-last parameter passing order for __stdcall and last-to-first order for __cdecl.

2) i doubt there''s a cross-platform way to do that. for win32, look for SEH to C++ EH translators (should be able to find some info in msdn/msj). i also think catch(...) will beside other things catch SEH exceptions, but don''t trust me on this.

there''s std::bad_alloc that indicates out-of-memory condition for new. besides that, "out of memory" is not strictly speaking an exceptional condition in the same sense as a divide-by-zero or access violation are.
quote:Original post by Crispy
2) does C++ have built-in standard exception (div by zero, out of mem, etc) handlers that can be caught without explicitly throwing them? std::xxx handlers don''t seem to be catching excptions that can normally be caught with the general catch(...) statement.

Allowing an arbitrary exception to be thrown is considered bad programming practice. The available standard exceptions are listed here and here (draft standard).

This topic is closed to new replies.

Advertisement