this post was submitted on 15 Jan 2025
111 points (93.7% liked)

Programming

17831 readers
43 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 [email protected]



founded 2 years ago
MODERATORS
 

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
[–] [email protected] 9 points 2 days ago (1 children)

CONST False = 0, True = NOT False

NOT as in the binary operator. What's NOT of 0 in a 32 bit space? 0xFFFFFFFF, which is -1, which is ≠ 1

Different languages, and even different programmers might interpret the concept and definition of True and False differently, so to save any ambiguity and uncertainty, defining your own critical constants in your own library helps make sure your code is robust.

[–] [email protected] 2 points 2 days ago (1 children)

So... all that is NOT False either, I presume?

[–] [email protected] 1 points 2 days ago (1 children)

they mean every bit is different

[–] [email protected] 0 points 2 days ago

I don't know; their comment seemed pretty much the same throughout...