1.
Why use
1 | enum { N = 1024 }; |
2.
1 2 3 4 5 6 7 | typedef struct BufHdr{ size_t len; size_t cap; char buf[0]; } #define buf__hdr(b) ((BufHdr *)((char *)b - offsetof(BufHdr, buf))) |
In define buf refers to char buf[0] in the struct.
But in grow function
1 2 3 4 5 | void *buf__grow(const void *buf, size_t new_len, size_t elem_size) { size_t new_cap = MAX(1 + 2*buf_cap(buf), new_len); assert(new_len <= new_cap); size_t new_size = offsetof(BufHdr, buf) + new_cap*elem_size; ... |
buf refers to the parameter name. But the code works anyway. How come?
Oh and if someone could explain how to set up Visual Studio (2015) project so the debugger and such would work it would be greatly appreciated. I did not create a project but just opened a single .c file and can not compile and run the file.