static char st[][8192];
void foo ( int tab_size){
st = (char**) malloc ((tab_size+1)*sizeof(char)*8192);
}
I receive the compilation error in “malloc” line that st has incomplete type. What is wrong? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you don’t specify the size of the inner dimension for
st, the compiler doesn’t know how big it needs to be; hence the type is incomplete, and you never complete it before themalloccall.Since it looks like your intent is to allocate
stdynamically, go with Oli’s advice and declare it as a pointer to an 8192-element array ofchar:and rewrite your
mallocstatement assizeof *st==sizeof (char [8192])== 8192. This form is a bit cleaner and easier to read. Note also that in C, you don’t have to cast the result ofmalloc(unless you’re using a pre-C89 implementation, in which case, I’m sorry), and the practice is discouraged.This will allocate enough space to hold
tab_size + 1arrays of 8192 characters each.It is only within the context of a function parameter declaration that
T a[]declaresaas a pointer toT.