Live data from Hacker News

Generics in C without void* or macros – enabled by psychec

github.com

1–10 of 74 posts

Re: Generics in C without void* or macros – enabled by psychec

#3
post #2

You should never typedef a pointer to an object. That’s common knowledge amongst experienced C developers and an immediate red flag, even for myself normally welcoming of anything built with Haskell.

A red flag implying what, exactly?

Re: Generics in C without void* or macros – enabled by psychec

#4
post #2

You should never typedef a pointer to an object. That’s common knowledge amongst experienced C developers and an immediate red flag, even for myself normally welcoming of anything built with Haskell.

While I agree with this, I think it's a ridiculously common thing to see among major software vendors. A lot of Apple's APIs are typedef'd pointers to various structs.

Re: Generics in C without void* or macros – enabled by psychec

#5
post #2

You should never typedef a pointer to an object. That’s common knowledge amongst experienced C developers and an immediate red flag, even for myself normally welcoming of anything built with Haskell.

I'm not an expert C developer but can see some semantic benefits of typedefing a pointer.

Is this considered harmful because it hides the fact that you're dealing with a pointer in the first place?

Re: Generics in C without void* or macros – enabled by psychec

#7
post #2

You should never typedef a pointer to an object. That’s common knowledge amongst experienced C developers and an immediate red flag, even for myself normally welcoming of anything built with Haskell.

If it's an opaque pointer I see no reason to typedef it as there is zero way to dereference any struct members.

It's all semantic sugar anyway.

Re: Generics in C without void* or macros – enabled by psychec

#8
post #2

You should never typedef a pointer to an object. That’s common knowledge amongst experienced C developers and an immediate red flag, even for myself normally welcoming of anything built with Haskell.

Yeah, true. Although, the problem is lessened if properly abstracted away via opacity. MPFR (GNU multi-precision library) typedefs an array of size 1 holding its basic type, as opposed to just typedefing the struct of the basic type. This is (I think) purely so they don't have to put '&' in front of their "objects" when passing them around.

While I've great respect for the authors of that fantastic library, I only have this to say about the practice: Jeeesh!

Re: Generics in C without void* or macros – enabled by psychec

#10
Type generic expressions [1] already exist in C11. You can do this without a special compiler front-end if you need it, you would just need to define each variant by hand. These are supported in GCC and Clang with the -std=c11 flag.

[1]: http://www.robertgamble.net/2012/01/c11-generic-selections.h...

Post reply on HN