Breaking News
Design How-To

MATLAB-to-C translation, part 1: Pitfalls and problems

NO RATINGS
Page 1 / 2 Next >
More Related Links
View Comments: Newest First | Oldest First | Threaded View
luc_semeria
User Rank
Rookie
re: MATLAB-to-C translation, part 1: Pitfalls and problems
luc_semeria   12/4/2007 6:19:20 PM
NO RATINGS
Writing C code by hand is very error prone! Your comment is right on. The fact that such a simple example may lead to errors or differences of opinion speaks volume for the need for an automatic translation tool such as Catalytic MCS. The example above assumes memory gets allocated inside of functions. Function callers are then responsible for freeing that memory. The example works like this. The malloc corresponding to "free(sorted)" happens in "my_sort". The free corresponding to "y_out = malloc(...);" happens in the caller of "example1". Finally, "i+=1", "i++" and "i=i+1" are all valid loop increments that should lead to the same assembly code out of today's C compilers.

amigan50
User Rank
Rookie
re: MATLAB-to-C translation, part 1: Pitfalls and problems
amigan50   12/4/2007 2:20:48 PM
NO RATINGS
why i+=1 instead of simply i++? "malloc" without a corresponding "free" and vice versa is a bad idea! you free sorted which was not malloc-ed, and you malloc y_out without freeing it.

Flash Poll
Radio
LATEST ARCHIVED BROADCAST
Join our online Radio Show on Friday 11th July starting at 2:00pm Eastern, when EETimes editor of all things fun and interesting, Max Maxfield, and embedded systems expert, Jack Ganssle, will debate as to just what is, and is not, and embedded system.
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Times on Twitter
EE Times Twitter Feed
Top Comments of the Week