make handles bold.
This commit is contained in:
1 parent
f577242432
commit
69b87777e5
728 files changed
+3291
-3087
No files matched your search
+4
-4
@@ -26,15 +26,15 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @DanielcHooper
|
||||
**1/** **@DanielcHooper** ^1749857446179299815
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Nice - when you combine this with all the other tricks (arenas, stretchy buffers, strings with length, etc), C is a really nice language to use!
|
||||
|
||||
**2/** @vkrajacic
|
||||
**2/** **@vkrajacic** ^1749894222130397489
|
||||
|
||||
@DanielcHooper
|
||||
**@DanielcHooper**
|
||||
|
||||
Yes, C can almost feel like an entirely different language once you develop your own base technical layer.
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @MrJayLC
|
||||
**1/** **@MrJayLC** ^1749843481822900718
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Neat!
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @alurmanc
|
||||
**1/** **@alurmanc** ^1749842429367185567
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
I love this!
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @alurmanc
|
||||
**1/** **@alurmanc** ^1749843270354538761
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Shouldn't it be TransformArguments?
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @endu06
|
||||
**1/** **@endu06** ^1749930915566961088
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
How does default work? Do variable args bypass duplicate designator in initializer?
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @luis_reyes_x
|
||||
**1/** **@luis_reyes_x** ^1749940314951893348
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Very cool! Designated initializers is one thing I wish c++ had. C also lets you do a similar thing with arrays to initialize certain elements
|
||||
|
||||
|
||||
+4
-4
@@ -26,18 +26,18 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @falco_girgis
|
||||
**1/** **@falco_girgis** ^1750088968681750741
|
||||
|
||||
The only problem here is that you cannot do this in a header file that is going to be included within a C++ source file... However, what you can do is macro out the compound literal and provide a C++20 temporary object initializer with slightly different syntax if __cplusplus is defined..
|
||||
|
||||
**2/** @vkrajacic
|
||||
**2/** **@vkrajacic** ^1750226315876122748
|
||||
|
||||
@falco_girgis
|
||||
**@falco_girgis**
|
||||
|
||||
Yeah, I haven't tested that because my codebase is purely C nowadays.
|
||||
I'm not concerned about compatibility with C++. I understand that this is not always a choice, especially when working with a codebase you didn't start.
|
||||
|
||||
**3/** @falco_girgis
|
||||
**3/** **@falco_girgis** ^1750239118867546281
|
||||
|
||||
Tbh, I've never encountered a scenario with supporting C++ where you couldn't still pull all the tricks like this with modern C, if you are willing to invest in the infrastructure... That includes using _Generic() switches, which aren't supported in C++... I have a macro layer which you use to declare each type and its associated call which will compile to a _Generic statement in C or... a to C++20 anonymous generic lambda doing a series of compile-time conditionals on the generic type argument and mapping it to the appropriate logic based on its type... Yeah, it's a shitshow, but you write it once and it just works. lol. https://github.com/gyrovorbis/libgimbal/blob/79722a270d2a80651d08eb0158e803c9e4a2de6e/lib/api/gimbal/utils/gimbal_scanner.h#L366
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @JLakness
|
||||
**1/** **@JLakness** ^1955779942689726670
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
C++ functor method
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @YehorAvramenko
|
||||
**1/** **@YehorAvramenko** ^1955676990754934991
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
this one is amazing to be honest
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @gretzky00
|
||||
**1/** **@gretzky00** ^1955713762163409316
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Haven't gotten to this place, I gotta keep pushing forward till I get gigachad levels like you
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @heyitsvaishnav
|
||||
**1/** **@heyitsvaishnav** ^1955715131293491311
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
This is soo good, I did it in Typescript as well and my life is easier now........
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @peach2k2
|
||||
**1/** **@peach2k2** ^1955706381077496306
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
really cool, but this doesn't mean c is a good or nice language in modern standards.
|
||||
|
||||
|
||||
+24
-24
@@ -26,21 +26,21 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @EskilSteenberg
|
||||
**1/** **@EskilSteenberg** ^1955882027997069711
|
||||
|
||||
@vkrajacic @CaptainKraft
|
||||
**@vkrajacic** **@CaptainKraft**
|
||||
|
||||
Am i the only one who thinks this is terrible? Its incredibly confusing to read and you cant see what parameters you miss, the header file is a lot more complex to read too. You lose the WYIWYG nature of C. If you want this kind of ”clever” syntax why not use C++?
|
||||
|
||||
**2/** @vkrajacic
|
||||
**2/** **@vkrajacic** ^1955891241201127767
|
||||
|
||||
It might be confusing the first time you encounter it, because it's not used often in C codebases. But that's true for a lot of things in C, since you often have to invent better solutions (like strings or memory arenas).
|
||||
As I said, I use this sparingly, but where it is used, it has always provided a better API. Ideally, I strive for ZII, so I don’t need a way of setting default values and can use a designated initializers to override when needed. That’s the best case scenario, and most of my base layer functions work like that.
|
||||
This will not work with C++, as far as I know, because they messed up designated initializers. There are probably other ways to do it there, but I don’t want C++.
|
||||
|
||||
**3/** @EskilSteenberg
|
||||
**3/** **@EskilSteenberg** ^1955902981704180163
|
||||
|
||||
@vkrajacic @CaptainKraft
|
||||
**@vkrajacic** **@CaptainKraft**
|
||||
|
||||
I think its confusing every time you see it. If i read:
|
||||
|
||||
@@ -50,7 +50,7 @@ The code does not communicate, what this function can do or if I'm missing a par
|
||||
|
||||
You also have to read all parameters in the function with one more level of indirection and thats slow.
|
||||
|
||||
**4/** @vkrajacic
|
||||
**4/** **@vkrajacic** ^1955906904330297594
|
||||
|
||||
I don’t see how this is different from:
|
||||
void PushTransform(Rect rect, TransformParams params);
|
||||
@@ -65,9 +65,9 @@ The first one just calls the Ex version with some reasonable defaults.
|
||||
|
||||
This works fine in most cases, but if you have a lot of arguments, you either have to make many such function permutations or force the caller to pass in all arguments, even the ones they don’t care about.
|
||||
|
||||
**5/** @EskilSteenberg
|
||||
**5/** **@EskilSteenberg** ^1955943723918921910
|
||||
|
||||
@vkrajacic @CaptainKraft
|
||||
**@vkrajacic** **@CaptainKraft**
|
||||
|
||||
I don't like:
|
||||
|
||||
@@ -75,7 +75,7 @@ void func(StructOfInputs params);
|
||||
|
||||
You are hiding the input, and you are forcing a memory layout. I don't even like small structs like Dim2, and Rect because they force the caller to adopt the structures of the callee. Don't force me to live in your world.
|
||||
|
||||
**6/** @vkrajacic
|
||||
**6/** **@vkrajacic** ^1955966202896920993
|
||||
|
||||
There’s no hiding of any kind, it’s a public POD struct.
|
||||
|
||||
@@ -88,54 +88,54 @@ RectCreate(f32 minX, f32 minY, f32 maxX, f32 maxY);
|
||||
|
||||
Yes, it enforces memory layout, but that’s kind of the point of structs, bundling data that gets used together. And vectors are a prime example of that, especially in games and renderers, because they act as primitives and are ubiquitous throughout the code.
|
||||
|
||||
**7/** @vkrajacic
|
||||
**7/** **@vkrajacic** ^1955966771141230709
|
||||
|
||||
@EskilSteenberg @CaptainKraft
|
||||
**@EskilSteenberg** **@CaptainKraft**
|
||||
|
||||
Another example in my codebase would be length based strings. I’ve built the whole API on top of those. I don’t want to go around passing char *value, int length. The point of that abstraction is that I don’t have to do that.
|
||||
|
||||
**8/** @nicbarkeragain
|
||||
**8/** **@nicbarkeragain** ^1956132278159192430
|
||||
|
||||
@vkrajacic @EskilSteenberg @CaptainKraft
|
||||
**@vkrajacic** **@EskilSteenberg** **@CaptainKraft**
|
||||
|
||||
I don't think I could ever go back to writing C with naked arrays / strings. It's such a small cost to pass length (and capacity) around, it's so simple and makes C feel like a different language.
|
||||
|
||||
**9/** @daniel_collin
|
||||
**9/** **@daniel_collin** ^1956288958100324653
|
||||
|
||||
@nicbarkeragain @vkrajacic @EskilSteenberg @CaptainKraft
|
||||
**@nicbarkeragain** **@vkrajacic** **@EskilSteenberg** **@CaptainKraft**
|
||||
|
||||
Yeah, I'm building a whole new C codebase and I'm having a String type for sure. Makes things just nicer.
|
||||
|
||||
**10/** @NotAttained
|
||||
**10/** **@NotAttained** ^1956025229047693468
|
||||
|
||||
@EskilSteenberg @vkrajacic @CaptainKraft
|
||||
**@EskilSteenberg** **@vkrajacic** **@CaptainKraft**
|
||||
|
||||
What is the alternative though if it’s a big struct, do you just manually type out the parameters each time, even if they are largely the same?
|
||||
|
||||
**11/** @EskilSteenberg
|
||||
**11/** **@EskilSteenberg** ^1956035840863252846
|
||||
|
||||
@NotAttained @vkrajacic @CaptainKraft
|
||||
**@NotAttained** **@vkrajacic** **@CaptainKraft**
|
||||
|
||||
YES! Having to declare a variable of the struct an then assigning every member is far more cumbersome and error prone.
|
||||
|
||||
**12/** @vkrajacic
|
||||
**12/** **@vkrajacic** ^1956083523120492831
|
||||
|
||||
It is if you're typing them all out. But the whole point of the post was about when you DON'T want to do that.
|
||||
Ideally, you'd have them zero initialized or set with some default arguments, and then just override the ones you want, via designated initializer syntax.
|
||||
At that point, it becomes less cumbersome and less error prone, because the defaults are already set up for you. You don’t have to write them again.
|
||||
If you have lots of parameters, it's almost always the case that you don't need to set each one at the call site. If you only have a few, then a struct is unnecessary.
|
||||
|
||||
**13/** @vkrajacic
|
||||
**13/** **@vkrajacic** ^1956084512217338077
|
||||
|
||||
@EskilSteenberg @NotAttained @CaptainKraft
|
||||
**@EskilSteenberg** **@NotAttained** **@CaptainKraft**
|
||||
|
||||
For instance, old win APIs often take a long list of parameters. In many cases, you only need a couple of options and pass 0 to everything else, e.g. NtQueryDirectoryFile.
|
||||
|
||||

|
||||
|
||||
**14/** @Karyuutensei
|
||||
**14/** **@Karyuutensei** ^1956124826558468255
|
||||
|
||||
@vkrajacic @EskilSteenberg @NotAttained @CaptainKraft
|
||||
**@vkrajacic** **@EskilSteenberg** **@NotAttained** **@CaptainKraft**
|
||||
|
||||
To be honest, function parameters get confusing beyond 2-3. Named parameters are much better.
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @FrawaMudi
|
||||
**1/** **@FrawaMudi** ^1955896975330582796
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Honestly I don't know what I am looking at anymore
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @emh203
|
||||
**1/** **@emh203** ^1955793903548031362
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Bravo!
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @etozheya42
|
||||
**1/** **@etozheya42** ^1955797197108236796
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
Let's go 10k likes.
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @quantized_state
|
||||
**1/** **@quantized_state** ^1955925511575888092
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
instantly rewriting everything
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @siddhantCodes
|
||||
**1/** **@siddhantCodes** ^1955847027704627626
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
This is so cool!
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @k00lagin
|
||||
**1/** **@k00lagin** ^1956460989324710205
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
I may be just one like, but together we build the whole 10k.
|
||||
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ parent_post_id: "1749816169736073295"
|
||||
|
||||
## Branch
|
||||
|
||||
**1/** @CarloIlCugino
|
||||
**1/** **@CarloIlCugino** ^2005479710604894610
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
thank you!
|
||||
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ in_reply_to: ""
|
||||
|
||||
## Thread
|
||||
|
||||
**1/** @vkrajacic
|
||||
**1/** **@vkrajacic** ^1749816169736073295
|
||||
|
||||
C macro approach to using optional / default / named function params, using struct designated initializers.
|
||||
Mandatory values are passed first as standard function params (rect in the example).
|
||||
@@ -35,8 +35,8 @@ Especially useful when a zero value can be made a valid value.
|
||||
|
||||
Branches: [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-alurmanc-i-love-this]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-alurmanc-shouldnt-it-be-transformarguments-parameters-are]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-MrJayLC-neat]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-DanielcHooper-nice-when-you-combine-this-with-all-the-other]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-endu06-how-does-default-work-do-variable-args-bypass]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-23-luis_reyes_x-very-cool-designated-initializers-is-one-thing-i]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2024-01-24-falco_girgis-the-only-problem-here-is-that-you-cannot-do-this]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-13-YehorAvramenko-this-one-is-amazing-to-be-honest]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-13-peach2k2-really-cool-but-this-doesnt-mean-c-is-a-good-or]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-13-gretzky00-havent-gotten-to-this-place-i-gotta-keep-pushing]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-13-heyitsvaishnav-this-is-soo-good-i-did-it-in-typescript-as-well]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-13-JLakness-c-functor-method]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-emh203-bravo]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-etozheya42-lets-go-10k-likes]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-siddhantCodes-this-is-so-cool]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-EskilSteenberg-am-i-the-only-one-who-thinks-this-is-terrible-its]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-FrawaMudi-honestly-i-dont-know-what-i-am-looking-at-anymore]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-14-quantized_state-instantly-rewriting-everything]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-08-15-k00lagin-i-may-be-just-one-like-but-together-we-build-the]], [[archive/threads/vkrajacic/2024-01-23-c-macro-approach-to-using-optional-default-named/2025-12-29-CarloIlCugino-thank-you]]
|
||||
|
||||
**2/** @pATjako
|
||||
**2/** **@pATjako** ^1749816924685672759
|
||||
|
||||
@vkrajacic
|
||||
**@vkrajacic**
|
||||
|
||||
I started experimenting with that in my imgui as well, it is kinda neat, also you can make the same code work for C & C++ (with some limitation in argument ordering)
|
||||
Reference in new issue
Block a user