This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quick and dirty optional option struct via function overload via preprocessor trick. | |
* | |
* It contains a (pretty ugly) workaround that allows it to work on preprocessor that don't understand | |
* ", ##" GNU extension. It requires the preprocessor to accept zero length varargs, | |
* which is apparently implemented elsewhere. | |
*/ | |
#include <stdio.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quick and dirty optional option struct via function overload via preprocessor trick. | |
* | |
* requires C99 and gnu extension, for ", ## __VA_ARGS" | |
*/ | |
#include <stdio.h> | |
///////// Magic library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ns_send("foo", "bar"); | |
ns_send("foo", "bar", opts); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quicky and dirty optional arguments. Requires (ANSI) C99. | |
* | |
* Good: | |
* 1. Allows to convert any existing function to a optarg function. | |
* 2. Typed parameters. | |
* 3. Users can just use a real option struct. | |
* | |
* So so: | |
* 4. Simple defaults are possible but might result in compiler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quicky and dirty optional arguments. Requires (ANSI) C99. | |
* | |
* Good: | |
* 1. Allows to convert any existing function to a optarg function. | |
* 2. Typed parameters. | |
* | |
* So so: | |
* 3. Simple defaults are possible but might result in compiler | |
* warnings that can be suppressed but ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This a is dummy port of the Go option pattern to C. | |
* | |
* The option pattern is described somewhat obscurely in | |
* http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html | |
* | |
* TL;DR: provide a way for functions to accept optional arguments with the following properties: | |
* | |
* 1) backward compatible signature for functions that were born with no thought for options | |
* 2) allow defaults that are not the zero value of the option struct member value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is dummy port of the Go option pattern to C. | |
* | |
* The option pattern is described somewhat obscurely in | |
* http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html | |
* | |
* TL;DR: provide a way for functions to accept optional arguments with the following properties: | |
* | |
* 1) backward compatible signature for functions that were born with no thought for options | |
* 2) allow defaults that are not the zero value of the option struct member value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is dummy port of the Go option pattern to C. | |
* | |
* The option pattern is described somewhat obscurely in | |
* http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html | |
* | |
* In Go it already suffers from some boilerplate explosion, but it's somewhat manageable. | |
* Here it's even worse, so I'm afraid this is just to be used for educational purposes. | |
* | |
* To be fair, it should be possible to throw even some more preprocessor magic to |