0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

storage class 4: file, The C Puzzle book

Posted at

職業訓練
https://qiita.com/kaizen_nagoya/items/95368b63fa21d64271ec

Programmer, Day 6
https://qiita.com/kaizen_nagoya/items/632d8f191268e88eb86a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識, error(21), coding(28)
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

The C Puzzle Book
https://efrei.poupa.net/Programmation%20en%20C/Cours/The_C_Puzzle_Book.pdf

defs.h "The C Puzzle Book"
https://qiita.com/kaizen_nagoya/items/6d284651ac1244963bd9

sf4.c
#include "defs.h"
int i=1;
int main(void)
{
        auto int i, j;
        i = reset();
        for( j=1; j<=3; j++){
                PRINT2(d,i,j);
                PRINT1(d, next(i));
                PRINT1(d, last(i));
                PRINT1(d,new(i+j));
        }
}
sc4-1.c
static int i=10;
int next(int j){
        return(i+=1);
}

int last(int j){
        return (i-=1);
}
sc4-2.c
extern int i;
int reset(void){
        return (i);
}
bash

$ gcc sc4.c sc4-1.c sc4-2.c
sc4.c: In function ‘main’:
sc4.c:6:13: warning: implicit declaration of function ‘reset’ [-Wimplicit-function-declaration]
    6 |         i = reset();
      |             ^~~~~
In file included from sc4.c:1:
sc4.c:9:27: warning: implicit declaration of function ‘next’ [-Wimplicit-function-declaration]
    9 |                 PRINT1(d, next(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:9:17: note: in expansion of macro ‘PRINT1’
    9 |                 PRINT1(d, next(i));
      |                 ^~~~~~
sc4.c:10:27: warning: implicit declaration of function ‘last’ [-Wimplicit-function-declaration]
   10 |                 PRINT1(d, last(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:10:17: note: in expansion of macro ‘PRINT1’
   10 |                 PRINT1(d, last(i));
      |                 ^~~~~~
sc4.c:11:26: warning: implicit declaration of function ‘new’ [-Wimplicit-function-declaration]
   11 |                 PRINT1(d,new(i+j));
      |                          ^~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:11:17: note: in expansion of macro ‘PRINT1’
   11 |                 PRINT1(d,new(i+j));
      |                 ^~~~~~
/usr/bin/ld: /tmp/ccuuLhkh.o: in function `main':
sc4.c:(.text+0xcf): undefined reference to `new'
collect2: error: ld returned 1 exit status
sc4a.c
#include "defs.h"
int i=1;
int main(void)
{
        auto int i, j;
        i = reset();
        for( j=1; j<=3; j++){
                PRINT2(d,i,j);
                PRINT1(d, next(i));
                PRINT1(d, last(i));
                PRINT1(d,new(i+j));
        }
        return EXIT_SUCCESS;
}

ps4-1a.c
static int i=10;
int next(int j){
        return(i+=1);
}

int last(int j){
        return (i-=1);
}

int new(int i){
        static int j=5;
        return (i=j+=i);
}
bash
$ gcc sc4.c sc4-1.c sc4-2.c
sc4.c: In function ‘main’:
sc4.c:6:13: warning: implicit declaration of function ‘reset’ [-Wimplicit-function-declaration]
    6 |         i = reset();
      |             ^~~~~
In file included from sc4.c:1:
sc4.c:9:27: warning: implicit declaration of function ‘next’ [-Wimplicit-function-declaration]
    9 |                 PRINT1(d, next(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:9:17: note: in expansion of macro ‘PRINT1’
    9 |                 PRINT1(d, next(i));
      |                 ^~~~~~
sc4.c:10:27: warning: implicit declaration of function ‘last’ [-Wimplicit-function-declaration]
   10 |                 PRINT1(d, last(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:10:17: note: in expansion of macro ‘PRINT1’
   10 |                 PRINT1(d, last(i));
      |                 ^~~~~~
sc4.c:11:26: warning: implicit declaration of function ‘new’ [-Wimplicit-function-declaration]
   11 |                 PRINT1(d,new(i+j));
      |                          ^~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:11:17: note: in expansion of macro ‘PRINT1’
   11 |                 PRINT1(d,new(i+j));
      |                 ^~~~~~
inst19@teachB:~$ vi sc4-2.c
inst19@teachB:~$ gcc sc4.c sc4-1.c sc4-2.c
sc4.c: In function ‘main’:
sc4.c:6:13: warning: implicit declaration of function ‘reset’ [-Wimplicit-function-declaration]
    6 |         i = reset();
      |             ^~~~~
In file included from sc4.c:1:
sc4.c:9:27: warning: implicit declaration of function ‘next’ [-Wimplicit-function-declaration]
    9 |                 PRINT1(d, next(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:9:17: note: in expansion of macro ‘PRINT1’
    9 |                 PRINT1(d, next(i));
      |                 ^~~~~~
sc4.c:10:27: warning: implicit declaration of function ‘last’ [-Wimplicit-function-declaration]
   10 |                 PRINT1(d, last(i));
      |                           ^~~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:10:17: note: in expansion of macro ‘PRINT1’
   10 |                 PRINT1(d, last(i));
      |                 ^~~~~~
sc4.c:11:26: warning: implicit declaration of function ‘new’ [-Wimplicit-function-declaration]
   11 |                 PRINT1(d,new(i+j));
      |                          ^~~
defs.h:8:59: note: in definition of macro ‘PR’
    8 | #define PR(format, value) printf(#value" = %"#format"\t",(value))
      |                                                           ^~~~~
sc4.c:11:17: note: in expansion of macro ‘PRINT1’
   11 |                 PRINT1(d,new(i+j));
      |                 ^~~~~~
$ ./a.out
i = 1   j = 1
next(i) = 11
last(i) = 10
new(i+j) = 7
i = 1   j = 2
next(i) = 11
last(i) = 10
new(i+j) = 10
i = 1   j = 3
next(i) = 11
last(i) = 10
new(i+j) = 14
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?