/** * A very simple approach to getting private variables -- name them "private" * ten use get and set accessors exclusively to change/see their values * * @author gtowell * Created: April 21, 2021 * **/ #include #include typedef struct { int private1; } privNAM; /** * The get accessor for private1 * @param pn -- pointer to the structure to get value from * @return the value in private1 * **/ int getYear(privNAM* pn) { return pn->private1; } /** * The set accessor for private1 * @param pn -- pointer to the structure whose value is to change * @param yr -- the value to set * **/ void setYear(privNAM* pn, int yr) { pn->private1 = yr; } /** * Strunt constructor * **/ privNAM* makePrivNAM() { return malloc(1 * sizeof(privNAM)); } int main(int argc, char const *argv[]) { privNAM *pn = makePrivNAM(); setYear(pn, 1961); printf("%d\n", getYear(pn)); return 0; }