Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Do you think the length of an `int64_t[3]` array should be 3 or 24?

There should be functions to do both: sizeof(int64_t[3]) * sizeof(int64_t) for example to get bytes.

In this example, the base function should do bytes, and there should be a unicode function to count it in other ways.

I could be sizing to fit in a database, or send over the wire, or I might want visible space on the screen, or I might want to know how to move the cursor.

Each of those types of length should be supported.



> There should be functions to do both: sizeof(int64_t[3]) * sizeof(int64_t) for example to get bytes.

That's not what that does, the answer to the code you wrote is 192 because you're multiplying the same size factor twice.


No I'm not, read it again.

The first one has size 3, because there are 3 elements in the array. The second one has size 8 because an int64 is 8 bytes.


I'm just reporting facts, C's sizeof operator measures bytes, so sizeof(int64_t[3]) * sizeof(int64_t) is 192

You don't have to like it


I apologize, you are correct. It's been too long since I used c.

I should write instead: sizeof(int64_t[3]) / sizeof(int64_t) for length of array.

This does help my argument that Javascript length on a Unicode string should return bytes though :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: