Given a struct such as this:
struct a {
int b;
int c;
my_t d[];
}
What do I have to pass to malloc to allocate enough memory for a struct a where d has n elements?
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.
Using the variables for
sizeofwill ensure the size is updated if the types change. Otherwise, if you change the type ofdorvaryou risk introducing silent and potentially difficult-to-find runtime issues by not allocating enough memory if you forget to update any of the corresponding allocations.