Last active
August 29, 2015 14:15
-
-
Save hidsh/1bc75af5dfcb73414858 to your computer and use it in GitHub Desktop.
C99 example (よくつかいそうなのだけ)
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
| // C99 example | |
| // | |
| // $ gcc -std=c99 c99.c -o c99 | |
| #include <stdio.h> | |
| #include <stdbool.h> // bool, true, false | |
| // bool sample | |
| // return true if x is even, otherwise return false | |
| bool even_p(int x) | |
| { | |
| return (x % 2)? false:true; | |
| } | |
| // __func__ sample | |
| void hoge(void) | |
| { | |
| printf("here is %s() in file:%s at line:%d\n", __func__, __FILE__, __LINE__); | |
| } | |
| // compound literal | |
| typedef struct | |
| { | |
| int x; | |
| int y; | |
| } Point; | |
| void plot(const Point *p) | |
| { | |
| printf("x:%3d, y:%3d\n", p->x, p->y); | |
| } | |
| int main(void) | |
| { | |
| printf("odd: "); | |
| for(int i=0; i<20; i++) { | |
| if(even_p(i)) continue; | |
| printf("%d, ", i); | |
| } | |
| printf("\n"); | |
| hoge(); | |
| plot(&(Point){.x = 10, .y = 20}); | |
| } |
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
| $ gcc -std=c99 c99.c -o c99; ./c99 | |
| odd: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, | |
| here is hoge() in file:c99.c at line:18 | |
| x: 10, y: 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment