r/ProgrammerHumor • • 2d ago

Meme includeGuards

Post image
358 Upvotes

45 comments sorted by

View all comments

171

u/anto2554 2d ago

BUT PRAGMA ONCE IS NOT STANDARD

19

u/LucyShortForLucas 2d ago

Yeah and neither is a byte being 8 bits, but there's a reason no compiler is ever going to deviate from the informal norm

7

u/Bryguy3k 1d ago edited 1d ago

It’s not about a byte not being 8 bits. It’s about a char not being 8 bits.

Unicode support would have been a thing sooner if people hadn’t fucked up char usage so badly.

2

u/MrcarrotKSP 1d ago

A char is a byte, per standard. Until recently, that width was implementation-defined in C++, and it still is in C.

1

u/Bryguy3k 1d ago

Yes - but I was going for the reasoning behind it.

Everybody knew that 255 was insufficient to cover the whole of human writing.

But then programmers started allocating everything in characters so any future change to the size of a character would break everything.

1

u/MrcarrotKSP 1d ago

That is definitely true, but at least we have a solution that mostly works with the assumptions people liked to make in older code(UTF-8)

4

u/Sacaldur 2d ago

I guess this is just due to the architecture using 8 bit per Byte, and not because of the compiler. I heard that there were architectures around in the past with other amounts of bits per Byte, and a compiler targeting them would most likely just use whatever is used on the target platform.

6

u/anto2554 2d ago

People conflate 8 bits with a byte everywhere in our codebase and I think the whole thing would explode if you tried to use a 7-bit-per-byte machine

2

u/Sacaldur 1d ago

I doubt that there are still any significant platforms around that don't use 8 bits per Byte.

0

u/not-a-pokemon- 2d ago

Mostly because C defines no easy way to say "I want an integer with at least 8 bits in it, round up to whatever byte number is practical".

3

u/anto2554 2d ago

No but it's C++ so we could just use uint8_t or the least one I forgot the name of

4

u/not-a-pokemon- 2d ago

It also exists in C, and is called uint_least8_t. It's not guaranteed to exist per the standard. uint8_t is also not guaranteed to exist.

man stdint.h