Live data from Hacker News

How Structs Really Work in C

tenaciousc.com

1–10 of 14 posts

Re: How Structs Really Work in C

#3

Wouldn't the zero-length array potentially run into other memory?

It is only fit to be used for heap allocation, you allocate the size that you need (i.e. malloc( sizeof(struct video_file2) + ARRAY_SIZE) ). It wouldn't work as a local variable.

edit: I suppose one could use for globals or on the stack by casting a byte array ... I would find that to be unspeakably ugly but I don't write much C.

Re: How Structs Really Work in C

#5

Wouldn't the zero-length array potentially run into other memory?

That's why the usage changes to a struct pointer at that point. The struct pointer just maps parts of an existing data structure (like a video file) to its labels.

Re: How Structs Really Work in C

#6
Most seasoned C programmers understand every point in this post. Points 2 and 3 are indeed clever tricks, but they're tricks that you eventually have to employ if you're doing low level work. It's part of the beauty and allure of C.

Re: How Structs Really Work in C

#8
Meta comment:

"You don't know it yet, but you're...wrong."

I really really hate it when a posting starts off like this, then proceeds to tell me something anyone who considered themselves a C programmer would know.

Want to write a post about something kind of neat that people outside the field might not be up on? Cool, have fun. But don't start it out by being a rude ass. And this guy dedicates the first hundred words or so of his article to it.

Post reply on HN