4 ms·
From a tutorial at https://www.modula2.org/tutor/chapter11.php https://www.modula2.org/tutor/chapter11.php: > The ALLOCATE procedure requires 2 arguments, the
by wahern 3y ago
From a tutorial at https://www.modula2.org/tutor/chapter11.php https://www.modula2.org/tutor/chapter11.php:
> The ALLOCATE procedure requires 2 arguments, the first of which is a pointer which will be used to point to the desired new block of dynamically allocated menory, and the second which gives the size of the block in bytes. The supplied function TSIZE will return the size of the block of data required by the TYPE supplied to it as an argument. Be sure to use the TYPE of the data and not the TYPE of the pointer to the data for the argument.
So what happens if you pass the wrong value as the second argument to ALLOCATE? Does the compiler throw an error, or are you now risking a buffer overflow?
C has arrays. Arrays carry size. The problems in C are much more nuanced than people seem to suggest, and people exaggerate the extent to which other languages do better in this regard, though to be sure C has significant deficiencies.