works like a charm.
just some questions so i will understand it. if i do not use extern the compiler will create two pointers one local in .c and one in .h ? And would get faulty logic? Or is it like a forward declaration and extern is implied? How come i can not use static in .c and/or .h. I only want one instance? If I use const will the compiler only allocate memory once even its used in several threads or instances? And just another question. If I have a const int x how do i cast it to int so i do not get warnings? Is it just (int) x ? |
Quote:
Free your mind from the necessity to have two files (.h and .c) and come to peace with the idea to have just one file. This is what I have in my project - the file conceptually looks like this (let's call it 'data.c'): Code:
#define NUMBER_OF_ELEMENTS 3 Code:
gcc -Wall -Wextra -DINSTANTIATE_DATA -c data.c When one needs the data to become known in a function file (let's call it 'function.c'), he/she writes the file this way: Code:
#include <stdio.h> Code:
gcc -Wall -Wextra -c function.c If it's not clear how it works, ask specific questions. The conceptual advantage is that 'data.c' is both the prototype and the implementation. In fact, I am now thinking of expanding the approach to function files too. Please note that even in case of data declaration, i.e. in case of effectively telling Code:
extern const int some_const_int_array[NUMBER_OF_ELEMENTS]; A declaration like Code:
extern const int some_const_int_array[]; |
Thats a nice sulotion and i do understand it. And i use NUMBER_OF_ELEMENTS in all my arrays since i will get compile errors if i assign the wrong number of elements and thats easy to do.
|
All times are GMT -5. The time now is 09:40 PM. |