Forum Discussion
Altera_Forum
Honored Contributor
21 years agomalloc( )problem
Hello : data_written = (unsigned char *)malloc(0x1000); num=sizeof(data_written); The size of data_written should be 0x1000,But use the function sizeof,the num is 4 . I hav...
Altera_Forum
Honored Contributor
21 years agoThis is a fundamental C question, and I think you should go and invest in a copy of Kernighan and Ritchie "The C Programming Language". On page 135 it states
<div class='quotetop'>QUOTE </div> --- Quote Start --- C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. The expressions sizeof onject and sizeof(type name) yield an integer equal to the size of the specified object or type in bytes.[/b] --- Quote End --- i.e. in your code it will return the sizeof the type of data_written, which I assume is an unsigned char* given your cast. That is indeed 4 bytes on the Nios architecture