79

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!

you are viewing a single comment's thread
view the rest of the comments
[-] crimsonpoodle@pawb.social 4 points 13 hours ago

I guess in reading not until c99(see other comment); they just used integers in place of Booleans, in which case your readability statement makes more sense given the historical context

[-] __nobodynowhere@startrek.website 4 points 12 hours ago

stdbool.h's true and false are macros that expand to integers 1 and 0

C23 adds a proper bool type

[-] brisk@aussie.zone 1 points 4 hours ago

C99 has a proper boolean (_Bool), C23 makes true and false booleans (and properly gives _Bool the name bool without the macro)

[-] Flipper@feddit.org 2 points 7 hours ago

Only 50 years after it's creation.

[-] furrowsofar@beehaw.org 3 points 13 hours ago

For what it is worth. I learned C in 1990. Switched largely to Python in 1998.

[-] bluGill@fedia.io 1 points 13 hours ago

True is not zero in C. You can always compare a value to 0 if you need false but cumparing to any single value for true is wrong. Often functions will return some calculated value which would be zero for false and who cares - it isn't zero so return it for true. Thus all defines of true are suspect.

this post was submitted on 15 Jan 2025
79 points (92.5% liked)

Programming

17810 readers
515 users here now

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



founded 2 years ago
MODERATORS