Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
565 B

  1. #include <stdio.h>
  2. #include <math.h>
  3. typedef struct point {
  4. double x, y;
  5. } point;
  6. /*
  7. Nested anonymous struct declaration compiles with MS extensions only.
  8. So you have to use -fms-extensions flag with gcc / clang.
  9. C11 standard allows no typedef in the nested anonymous declaration :(
  10. */
  11. typedef struct {
  12. struct point;
  13. double z;
  14. } threepoint;
  15. double threelength(threepoint p) {
  16. return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
  17. }
  18. int main () {
  19. threepoint p = {.x = 3, .y = 0, .z = 4};
  20. printf("p is %g units from the origin\n", threelength(p));
  21. }