in reply to Re: OT: Why does malloc always give me 24?
in thread OT: Why does malloc always give me 24? [SOLVED]

The answer to "why 24" will be that allocating a single byte, or 4, probably doesn't make sense with the amount of bookkeeping data involved. That malloc implementation is probably just making the minimum size be 24, quite possibly for alignment reasons.

C99 has variable-length arrays (VLAs), which would allow this, where gizmo would be on the stack and evaporate on do_something's return:

void do_something(int n) { struct acme gizmo[n]; int i; for (i=0; i<n; i++) { /* do stuff */ } }

The code above has a syntax error: gizmo* = (acme*)malloc(sizeof(acme) * N) has an unnecessary "*" after "gizmo".