For controling struct members and force programmers to use getter/setter functions, I want to write code like below pattern:
/* Header file: point.h */
...
/* define a struct without full struct definition. */
struct point;
/* getter/setter functions. */
int point_get_x(const struct point* pt);
void point_set_x(struct point* pt, int x);
...
//--------------------------------------------
/* Source file: point.c */
struct point
{
int x, y;
};
int point_get_x(const struct point* pt) {return pt->x; }
void point_set_x(struct point* pt, int x) {pt->x = x;}
//--------------------------------------------
/* Any source file: eg. main.c */
#include "point.h"
int main()
{
struct point pt;
// Good: cannot access struct members directly.
// He/She should use getter/setter functions.
//pt.x = 0;
point_set_x(&pt, 0);
}
But this code does not compile with MSVC++ 2010.
Which changes should I do for compiling?
Note: I use ANSI-C (C89) standard, Not C99 or C++.