LoginSignup
8
8

More than 5 years have passed since last update.

C言語のmain関数のラッパー

Posted at

目的

main.cに書かれたmain()関数がある.

main.c
#include <stdio.h>
int main()
{
  printf("hello world\n");
  return 0;
}

これを外から呼び出す.

newmain.c
#include <stdio.h>
int _main();

int main()
{
  printf("new main\n");
  _main();
  printf("new main\n");
  return 0;
}
#define main _main
#include "main.c"

build & run

実行
$ gcc -o newmain newmain.c
$ ./newmain
new main
hello world
new main
$ 

用途

  • 初心者の学生が書いたmain関数のチェック.
8
8
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
8
8