I’m working through the vulkan tutorial and came across GLFW_TRUE and GLFW_FALSE. I presume there’s a good reason but in looking at the docs it’s just defining 1 and 0, so I’m sorta at a loss as to why some libraries do this (especially in cpp?).

Tangentially related is having things like vk_result which is a struct that stores an enum full of integer codes.

Wouldn’t it be easier to replace these variables with raw int codes or in the case of GLFW just 1 and 0?

Coming mostly from C, and having my caps lock bound to escape for vim, the amount of all caps variables is arduous for my admittedly short fingers.

Anyway hopefully one of you knows why libraries do this thanks!

24 points

GLFW is a C library, not a C++ one, and an old one at that, and so the reason is that a long time ago, there was no bool in C. Every library would make their own true and false bc it’s handy to have.

Nowadays, the type _Bool has been added to C, and C++ has built-in bool, but you can still see the legacy of no boolean in C as to use the type name “bool” as well as the key words “true” and “false” for 1 and 0, you have to include “stdbool.h,” as well as in custom types in these old GL-adjacent libraries.

permalink
report
reply
41 points

I work with young people starting out in IT, so I’m used to getting screenshots, and I’m so used to screenshots made with a phone instead of just capturing the screen, that I’ve stopped complaining… But come on! At least evaluate the result of the first picture and maybe do another if it’s illegible.

permalink
report
reply
3 points

Yeah that’s fair— this is my focus workstation so don’t have any messaging apps or email to send the screenshot but def could have taken a second picture.

permalink
report
parent
reply
40 points

My brain is so used to seeing political content that I read “why do liberals define their own true and false” and was already like “what kind of shit take am I going to have fun reading today”

permalink
report
reply
4 points

That should probably be red alert wakeup call for you right?

permalink
report
parent
reply
2 points

Why?

permalink
report
parent
reply
9 points

I can give you a shit take if you want one, but I don’t have shiitake mushrooms.

permalink
report
parent
reply
2 points

I like my shit takes wrapped in beef rolls, in case you come across some more :)

permalink
report
parent
reply
5 points

i just like namespacing my variables anyway so there’s no chance of any conflicts and so you can easily change something one place instead of everywhere

permalink
report
reply
69 points

This is often done for backward compatibility, as stdbool.h which provides true and false wasn’t standard before C99 and even though that’s more than 25 years ago now a lot of old habits die hard.

permalink
report
reply
33 points

Also, plenty of embedded systems don’t use the C standard library.

permalink
report
parent
reply
1 point

stdbool.h (along with float.h, limits.h, stdarg.h, stddef.h, stdint.h, and some other library facilities) is required to be provided even in freestanding environment so, at least as long as you use an ISO C conformant compiler, you can always include those even if you don’t have a libc implementation

permalink
report
parent
reply
10 points

Yeah in the late 90’s I was coding in C++ and I’m pretty sure I had to define true and false manually.

permalink
report
parent
reply
5 points

I seem to recall using the true and false literals C++ in the late '90s … looks like they were in the C++98 standard, but it’s not clear which pre-standard compilers might have supported them.

permalink
report
parent
reply
7 points

Ahh this makes some sense

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 2.5K

    Monthly active users

  • 1.9K

    Posts

  • 30K

    Comments