code optimization and parameters marshalling question

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

Reply to
Zigbee
Loading thread data ...

not

It won't work!

Reply to
Lanarcam

not

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

Reply to
Lanarcam

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

Reply to
Zigbee

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
Reply to
CBFalconer

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

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

--
Richard
Reply to
Richard

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

optimize

and

optimizing

like

This is preferrable, provided you have the source code!

Reply to
Lanarcam

"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
Reply to
Richard

options

You, *spoiled* ones :)

Reply to
Lanarcam

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
Reply to
CBFalconer

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.

Reply to
Lanarcam

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
Reply to
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

Reply to
Lanarcam

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.

Reply to
Chris Giese

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 !
Reply to
42Bastian Schick

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.