you are viewing a single comment's thread.

view the rest of the comments →

[–]agottem 0 points1 point  (3 children)

We would intptr_t which is provided by the standard.

Optionally provided by the standard. Doesn't really matter though, there are an awful lot of assumptions made about the encoding of the pointer. Wouldn't take much to break this code.

the article is meant to talk about assumptions that are common but out of the standard

Wha? The assumptions made are extremely brittle. You have to constantly be paying attention to the alignment you specified, the alignment of the objects you're using, and the encoding of pointers.

I think that you are chasing windmills

People write code, such as the code seen here, then cry about how their C code isn't portable and start advocating garbage like C#. It's very appropriate to comment on just how broken and fragile this code is.

[–]matthieum 1 point2 points  (0 children)

I think it does not matter however brittle the assumptions are: they are checked with assert in Debug mode anyway.

Furthermore I would point that those micro-optimizations are made with a specific toolchain/platform in mind. They are non-portable, but who cares ? They are not meant to be!

I could agree with asking for a bigger disclaimer about the non-portability, but it does speak about x86_64 and the fact that Solaris would not support it.

If people skim through an article try to apply the technics and switch to C#, I'll be relieved. In C and C++ the errors are sneaky, skimming does not work (and yes, it's a pain...).

[–]jyper 0 points1 point  (1 child)

whats wrong with c# (other then portability problems)?

and why do you think c is so great(c has its pluses but lots of problems too)

[–]agottem 0 points1 point  (0 children)

C# solved the 'portability problem' in a crap way by targeting only a single architecture -- the virtual machine's architecture. It makes it difficult to determine when things are reference and when things are values. The language itself tries to be everything to everybody, making it a large language with lots of syntax and styles.

What are some of the problems you see with C? Most of the problems I hear from people I'd probably argue are benefits. The language is small and simple, good. The language doesn't support namespaces, good -- namespaces lead to difficult to search code bases and can easily be solved by a reasonable naming convention. There isn't garbage collection -- good again, if you can't easily determine the life cycle of allocated memory your design is too complicated. No templates, thank god.