This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Compiletime created instances from function.


Hi

I have my own string class and a function called s that creates an instance of a string initialized by a cstring. This can sometimes be a bit time consuming so I wrote a struct that would equal the class.

typedef struct {
   void* vtable;
   int classtype;
   int retaincount;
   int bytes;
   const char* storage;
   int option;
} foo;

Creating an instance of foo and casting it to my real string class work gives me a working string. Now what I would like to do is to put this struct into the .data section and have s return a pointer to this instance.

There is 3 things that I haven't got working
1) Have s put the instance in .data and return the pointer. I tried using __attribute__((section("data"))) but it seems it cannot be used with local variables, which actually seems logical.
2) Get a pointer to the string vtable at compile time and put this in the structs. It's easy to get it at run-time thought.
3) The string s takes as argument should also be put into the struct.


The linker should be able to resolve 2 & 3, I just don't know how. I also figured that s should be replaced with a macro instead.

Is this even possible to do?


--



//*David Sveningsson [eXt]*


Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]