From d74f8435ea7479fe558efa63c2ecc9aed5662db2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 13 Jan 2014 11:45:34 +0100 Subject: docs: tweak keep_data_small.txt Signed-off-by: Denys Vlasenko --- docs/keep_data_small.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt index 9fc799646..3ced1a61d 100644 --- a/docs/keep_data_small.txt +++ b/docs/keep_data_small.txt @@ -103,7 +103,15 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro: SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); -Typically it is done in _main(). +Typically it is done in _main(). Another variation is +to use stack: + +int _main(...) +{ +#undef G + struct globals G; + memset(&G, 0, sizeof(G)); + SET_PTR_TO_GLOBALS(&G); Now you can reference "globals" by G.a, G.buf and so on, in any function. -- cgit v1.2.3