Is there a difference between how LCC compiles a file and how MS visual studo compiles the same file?
1 view (last 30 days)
Show older comments
While running a simulation on MATLAB/SIMULINK, one of the blocks is an s-function written in C++. Compiling the C++ files with two different compilers, namely LCC and MS visual studio 2008 gives 2 different sets of results out of the simulator. Is there any obvious difference between the two compilers which would lead to a difference in the results? and when I say difference, using the visual studio 2008 compiler leads to values of the order of 10^250 which is clearly wrong. Has anyone encountered a similar problem before?
0 Comments
Answers (1)
James Tursa
on 9 Aug 2012
LCC is a C compiler, not a C++ compiler. LCC cannot compile C++ code, so I assume that you really have C code and not C++ code. That being said, Visual C is generally vastly superior to LCC as far as optimization is concerned. I have seen cases where the compiled code it generated ran 3x - 10x faster than the code that LCC generated. But for correctly written code and a good algorithm I would not expect the results themselves to differ much. Without seeing your code I would hazard a guess that there is a coding problem, but that is just a guess. Can you post your code?
2 Comments
James Tursa
on 23 Aug 2012
What you are experiencing is a classic symptom of a missing prototype for a function and/or mismatched macro or typdef between a library function and your code. I suspect you are missing a needed header .h file from your source code. E.g., you might have a function that returns a char but it is missing a prototype, so the compiler assumes it returns an int and grabs garbage bits from a register for the return value (32 bits, 24 of which are garbage). By inserting a printf call, however, the printf function returns an int, which would have the effect of clearing the 24 garbage bits to 0 (typically) in the return register that your other function uses so you don't notice the coding error. I would look for missing header .h files or incorrect DEFINE's or typedef's. If you are not sure which functions are missing prototypes, rename the file to a .cpp file and compile it with Visual C++. Since C++ requires prototypes the compiler will complain each time it encounters such a function.
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!