Skip to content

Instantly share code, notes, and snippets.

@AdnoC
Last active August 29, 2015 14:07
Show Gist options
  • Save AdnoC/cdbba9807853aa2f7605 to your computer and use it in GitHub Desktop.
Save AdnoC/cdbba9807853aa2f7605 to your computer and use it in GitHub Desktop.
/r/learnprogramming post part 1
#include<iostream>
using namespace std;
// I had three types of structs. One contained another. That one contained an array of an other as well as a pointer to one.
struct Bar {
int value1;
};
struct Foo {
Bar bars[5];
Bar *next;
};
struct Foobar {
Foo foo;
};
// I also had a function that initialized them.
void Bar_initialize(Bar *bar, int v1) {
bar->value1 = v1;
}
void Foo_initialize(Foo *foo) {
for(int i = 0; i < 5; i++) {
Bar_initialize(foo->bars + i, i);
}
foo->next = foo->bars;
}
void Foobar_initialize(Foobar *fb) {
Foo f;
Foo_initialize(&f);
fb->foo = f;
}
// There were also other functions that did stuff with the structs
void print_foobar(Foobar *fb) {
for(int i = 0; i < 5; i++) {
cout << fb->foo.next->value1 << endl;
fb->foo.next++;
}
}
void do_something(Foobar *fb) {
print_foobar(fb);
}
int main() {
Foobar fb;
Foobar_initialize(&fb);
do_something(&fb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment