Created
May 29, 2013 02:48
-
-
Save stephenmm/5667650 to your computer and use it in GitHub Desktop.
This is an example of getting named function parameters with c99 code. Didn't work out of the box for C++ but I think there may be a way to get it to work for C++ as well.
This file contains 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
/** To compile: | |
gcc -Wall -c named_func_params.c -o named_func_params.o && \ | |
gcc named_func_params.o -lm -o named_func_params.x && \ | |
named_func_params.x | |
*/ | |
#include<stdio.h> | |
typedef struct funcParams_s{ | |
int UID; | |
char uid_char[24]; | |
unsigned portIndex; | |
}funcParams_t; | |
void func1( funcParams_t params ){ | |
printf("params.UID: %i\n",params.UID); | |
} | |
void func2( funcParams_t* params ){ | |
printf("params->UID: %i\n",params->UID); | |
} | |
int main() { | |
funcParams_t a; | |
a = (funcParams_t){ .UID = 123, .portIndex = 0 }; | |
func1( a ); | |
func1( (funcParams_t){ .UID=456 } ); | |
func2( &(funcParams_t){ .UID=789 } ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment