Is there a difference between how LCC compiles a file and how MS visual studo compiles the same file?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
James Tursa
2012-8-9
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 个评论
James Tursa
2012-8-23
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!