code optimization and parameters marshalling question

Mar 29, 2005 14 Replies

Hi folks,



I've recently discovered that if I ask my NC30 compiler to optimize my C code, it passes function parameters through the registers and not through the stack. The question is:



What happens if I call a function that belongs to a library which was compiled using optimizing options (parameters passed through the registers), from a function that was compiled without optimizing options (parameters passed through the stack)?



thanks, Enrico


not

It won't work!

not

You could try to enable optimization with pragma directives in the portions of code that call the library routines.

thanks!

I in fact suspected that.... That explains why, in the past, each time I tried to enable any kind of optimization, I experienced problems...

ciao, Enrico

There should be some way of indicating the fact in the headers, similar to the use of 'fastcall' in Microsoft systems. Check your documentation. Once you use such things you are getting outside of standard C. At any rate the library headers should handle it.

"If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson

Zigbee wrote in news: snipped-for-privacy@individual.net:

And this is why you recompile your libraries when you change options like that.

Richard

news: snipped-for-privacy@individual.net:

optimize

and

optimizing

like

This is preferrable, provided you have the source code!

"Lanarcam" wrote in news:1112109043.966756.318420 @g14g2000cwa.googlegroups.com:

Well, yes, but then, where I work, we generally don't use any library that we can't get the source for, or RTOS for that matter.

Richard

options

You, *spoiled* ones :)

No, just practical, IMO.

"If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson

I have just made a proposal for a prospective customer who won't accept to pay too high a price for a basic functionality. This is a problem of balance between safety levels and costs.

As for the original problem, a solution could be to wrap calls to the library and place them in a separate source file which is compiled with optimizations enabled. This is possible if you can afford the time penalty.

CBFalconer wrote in news:4249812E.716D6094 @yahoo.com:

Yep, that is one of the primary considerations when we are out shopping for one of the above.

Richard

I have just made a proposal for a prospective customer who won't accept to pay too high a price for a basic functionality. This is a problem of balance between safety levels and costs

Check if your compiler supports the "cdecl" keyword (or maybe "Cdecl", "_cdecl", etc.) This keyword tells the compiler to use the normal, stack-based calling convention.

The compiler may also have a command-line option to force the use of the stack calling convention, even with optimizations enabled.

Or you should have received two (or more ) kinds of libraries.

42Bastian Do not email to bastian42@yahoo.com, it's a spam-only account :-) Use @monlynx.de instead !

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required