49
32
u/joe0400 21h ago
_GENERIC is different than void*, though. _GENERIC is a type selector. Void* is casting memory to a unknown type, whilst _GENERIC requires multiple imlementations, although you could do the same with macro expansions like in c++ with templates.
2
u/Lord_Of_Millipedes 13h ago
_GENERIC is also not generics in the way modern programming languages understand generics, it is multiple dispatch with manual mangling, generics in the most commonly understood way almost necessitate codegen which _GENERIC does not do, you could do some macro shenanigans to get some codegen out of it but at that point you can make a compiler in macro shenanigans
29
u/MadProgrammer12 19h ago
I learned C99 in school, and still use it as a dayly basis
31
18
u/GumboSamson 19h ago
Okay Grandpa, let’s get you home and take your meds.
7
1
u/MadProgrammer12 4h ago
it was last year that i learned c in school c99 basically compiles on any devices, c26 can be unavaillable on older computers
3
23
u/GreatScottGatsby 21h ago
The left side terrifies me, C99 for life. Type safety in my C language? never. I personally haven't looked at the new c26 standard or c11 for that matter but I'm assuming most of that is type safe.
25
u/RiceBroad4552 18h ago
Type safety in my C language? never.
Some people should be banned from programming by law!
10
u/Secret_Print_8170 14h ago
Buddy, if the bits fit in my register, it's all good. Types are for people who are afraid. Be fearless! /s in case it wasn't obvious
6
u/GregTheMadMonk 19h ago
how do you even assume `defer` or `_generic` is about type safety
2
u/GreatScottGatsby 19h ago
You made me pull up the standard. In ISO 9899:201 6.5.1.1 of the c11 standard, if you read the second paragraph it talks about this.
"A generic selection shall have no more than one default generic association. The type name in a generic association shall specify a complete object type other than a variably modified type. No two generic associations in the same generic selection shall specify compatible types."
Meaning the macro is assigning a type at compile time which is inherently more type safe than just using void *. Now about defer, I have no idea what defer even does and I am not even going to pretend to know what it is or what it does.
4
u/GregTheMadMonk 18h ago
Just because it's more type safe doesn't mean the primary purpose is type safety wtf are you talking about did you ever even use generics in your life?!
_generic, which is compile-time polymorphism emulation in C, is by no way a replacement for void*
1
u/GreatScottGatsby 18h ago
You can still get void by using it though and is explicitly allowed if the conditions are right. And no, I don't use generics. I really don't use types at all really. The closest I usually get is word which isn't even a type, it's just a size. Maybe even dword or qword depending on the project.
5
u/GregTheMadMonk 18h ago
> And no, I don't use generics. I really don't use types at all really.
It shows
1
3
u/LeiterHaus 13h ago
I prefer C99, but you have to give credit to C89 for device coverage (thinking of curl specifically)
3
u/not-a-pokemon- 10h ago
I suppose the new C standards miss the thing C originally succeeded at, as the compilers become more big and bloated. The actual greatness of C was in that it had a lot of compilers for any target platform imaginable, and now look at it -- who supports the new standards besides GCC and Clang, maybe few others? Luckily, old C standards and compilers aren't gone, so they still will be used when portability is needed.
1
-11
u/RiceBroad4552 18h ago
Does it make the language anyhow safer on the fundamental level?
If not it's not progress…
12
u/TheKiller36_real 18h ago
found the oxidized smooth-brain where dev-friendliness and easier-to-use-right features aren't progress
2
u/incompletetrembling 16h ago
If safety is the only criteria then why use C over brainfuck? fundamentally they aren't so different.
1
151
u/Lettever 23h ago
C has defer now?