Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor C sample #47

Merged
merged 8 commits into from
May 25, 2020
Merged

Refactor C sample #47

merged 8 commits into from
May 25, 2020

Conversation

Tiryoh
Copy link
Contributor

@Tiryoh Tiryoh commented May 20, 2020

Checklists

  • I have read the CONTRIBUTING document.
  • I have checked to ensure there aren't other open Pull Requests for the same change.

What does this implement/fix? Explain your changes.

現状のコードでもコンパイルして問題なく動いていますが、以下の理由によりmain関数をint型にしたほうが良いと思います。

  • フリースタンディング環境ではなくホスト環境でのプログラムであること
  • コンパイル時に明確にC99を指定していないこと

現状ではコンパイル時に以下のワーニングが出るので、まとめてリファクタリングしています。

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/7/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 

$ gcc step1.c -o step1 -Wall
step1.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(void)
      ^~~~
step1.c: In function ‘main’:
step1.c:17:13: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
             write(led[i],"1",1);
             ^~~~~
step1.c:19:9: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
         usleep(500*1000);
         ^~~~~~
step1.c:28:9: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
         close(led[i]);
         ^~~~~

$ gcc step2.c -o step2 -Wall
step2.c: In function ‘_Getch’:
step2.c:6:2: warning: implicit declaration of function ‘system’ [-Wimplicit-function-declaration]
  system("stty -echo -icanon min 1 time 0");
  ^~~~~~
step2.c:7:7: warning: implicit declaration of function ‘getchar’ [-Wimplicit-function-declaration]
  ch = getchar();
       ^~~~~~~
step2.c: At top level:
step2.c:12:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(void){
      ^~~~
step2.c: In function ‘main’:
step2.c:19:5: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
     write(buzzer,"0",2);
     ^~~~~
step2.c:66:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
  close(buzzer);
  ^~~~~


$ gcc step3.c -o step3 -Wall
step3.c: In function ‘get_SW0’:
step3.c:7:2: warning: implicit declaration of function ‘read’; did you mean ‘creat’? [-Wimplicit-function-declaration]
  read(SW0,buf,2);
  ^~~~
  creat
step3.c:8:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
  close(SW0);
  ^~~~~
step3.c: At top level:
step3.c:32:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(void){
      ^~~~
step3.c: In function ‘main’:
step3.c:45:4: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
    usleep(10000);
    ^~~~~~
step3.c:50:5: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
     write(LED3,"0",1);
     ^~~~~

$ gcc step4.c -o step4 -Wall
step4.c:5:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(void)
      ^~~~

$ gcc step5.c -o step5 -Wall
step5.c:5:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(void)
      ^~~~

Does this close any currently open issues?

しません。

@Tiryoh Tiryoh self-assigned this May 20, 2020
@Tiryoh Tiryoh added the Type: Refactoring A code change that neither fixes a bug nor adds a feature label May 20, 2020
@Tiryoh Tiryoh marked this pull request as ready for review May 25, 2020 06:19
@Tiryoh Tiryoh marked this pull request as draft May 25, 2020 06:20
@Tiryoh Tiryoh requested a review from ShotaAk May 25, 2020 06:26
@Tiryoh Tiryoh assigned ShotaAk and unassigned Tiryoh May 25, 2020
@Tiryoh Tiryoh marked this pull request as ready for review May 25, 2020 06:26
Copy link
Contributor

@ShotaAk ShotaAk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動作確認しましたOKです

@ShotaAk ShotaAk merged commit af0c46a into master May 25, 2020
@ShotaAk ShotaAk deleted the pr/refactor_c_sample branch May 25, 2020 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Refactoring A code change that neither fixes a bug nor adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants