Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kazmura11
Created February 6, 2015 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazmura11/392e52c2b1ca9f671bdd to your computer and use it in GitHub Desktop.
Save kazmura11/392e52c2b1ca9f671bdd to your computer and use it in GitHub Desktop.
C言語のヘッダの書き方(a.c)
#include "a.h"
#include <stdio.h>
#include "Global.h"
// 構造体の完全な定義を書く
typedef struct tag_bar
{
int a;
int b;
char c[4];
} Bar;
// 要はprivateのようなもの
// この中だけで使う関数
static void bar_proc_1(Bar *bar);
static void bar_proc_2(Bar *bar, int n);
// この中だけで使うグローバル変数はstaticに
static int g_internal;
void bar_proc()
{
Bar bar = { 1, 2, "abc"};
bar_proc_1(&bar);
bar_proc_2(&bar, 1);
// ...
g_foo = -1;
printf("[%s] g_foo : %d\n", __func__, g_foo);
g_FooBar.a = -1;
g_FooBar.b = -2;
printf("[%s] g_FooBar.a : %d, g_FooBar.b : %d\n",
__func__, g_FooBar.a, g_FooBar.b);
}
void bar_proc_1(Bar *bar)
{
printf("[%s] called.\n", __func__);
// ...
}
void bar_proc_2(Bar *bar, int n)
{
printf("[%s] called.\n", __func__);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment