Archived

This topic is now archived and is closed to further replies.

Crispy

2 questions

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites