ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I still don't quite understand, it, but it is starting to look like an object.
And I misunderstood the meaning of the curly braces last time, does the part in the curly braces really exist like a separate program or what?
The part in curly braces exists as a separate name space for stack (auto) variables and and function names - the latter is true for GNU C99, not for ANSI C99.
I'll try to develop the example further, i.e. to really make it an object with data encapsulation, constructor and destructor.
Is it possible to count the number of pointers to a block of allocated memory?
This would allow me to have a global variable containing a structure defining things common to all instances of a class, so that that information will not be redundantly held in each instance. The variable will initially be NULL, if a constructor is called and the class is NULL, it is created, and when all instances of the class are destroyed, the class variable will bee freed and set to NULL again.
Is it possible to count the number of pointers to a block of allocated memory?
This would allow me to have a global variable containing a structure defining things common to all instances of a class, so that that information will not be redundantly held in each instance. The variable will initially be NULL, if a constructor is called and the class is NULL, it is created, and when all instances of the class are destroyed, the class variable will bee freed and set to NULL again.
Sorry, I'm busy lately. Still, I found that, on the one hand, GCC closures are not good enough, on the other hand, Apple in its "C" language family + LLVM has what they call "blocks" - this should be sufficient.
llvm-gcc now supports a C language extension known as "Blocks". This feature is similar to nested functions and closures, but does not require stack trampolines (with most ABIs), and supports returning closures from functions that define them. Note that actually using Blocks requires a small runtime that is not included with llvm-gcc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.