const:
const int i = 5;
Hoever, , , . , .
, , const, undefined bahaviour , , , const .
, static ( ), - / ( static). setter/getter:
"wrapper.h":
#ifndef WRAPPER_H
#define WRAPPER_H
extern void set_once(int v);
extern int get_value(void);
#endif
"wrapper.c":
#include <stdbool.h>
#include "wrapper.h"
static struct {
bool is_set;
int value;
} my_var;
void set_once(int v)
{
if ( !my_var.is_set )
my_var.value = v;
else
;
}
int get_value(void)
{
if ( !my_var.is_set )
return my_var.value;
}
"main.c"
#include "wrapper.h"
int main(void)
{
set_once(5);
int i = get_value();
}
, , . , , 0 ( false).
, , , , / (, assert).
Edit:
. , , , . , , . gcc- , -fplan9-extensions. .
@MattMcNabb.