Skip to content

Commit

Permalink
Cast result of malloc
Browse files Browse the repository at this point in the history
This is common practice in MSL.
It is mandatory when compiling external C code as C++.
Also mind the later cast in "return (void*) table" that is
neither required by C nor by C++, nevertheless expressing the intention.
  • Loading branch information
rfranke authored and dietmarw committed Aug 9, 2023
1 parent ce36c07 commit 4e3bb74
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ModelicaReference/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ The external C-functions may be defined in the following way:
} MyTable;

<strong>void</strong>* initMyTable(const char* fileName, const char* tableName) {
MyTable* table = malloc(sizeof(MyTable));
MyTable* table = (MyTable*) malloc(sizeof(MyTable));
<strong>if</strong> ( table == NULL ) ModelicaError(\"Not enough memory\");
// read table from file and store all data in *table
<strong>return</strong> (void*) table;
Expand Down

0 comments on commit 4e3bb74

Please sign in to comment.