Re: Newbie question
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 17 Dec 2005 12:55:03 +0000
Longfellow wrote:
I would like the opinions of the experts here, hopefully in agreement.
I've developed the bones of an application with a C backend and a Gtk front end (NB gtk compiles with the -ansi switch and so is legitimate to mention in this forum).
Gtk is still off topic. Do you expect us to know all the libraries and applications written in C? There are literally thousands (or more) of them, and if we covered them all this group would be of no use because you would not be able to find the interesting (to you) stuff amongst all the rest. Of course, if you posted part of the Gtk source written in standard C we could discuss it and that would be fine.
BTW, since GTK does graphics, by definition it cannot be entirely standard C since standard C provides no mechanism for doing graphics.
> I've not been able to get them to talk directly
to each other in a reliable manner, so I've set it up for them to use the same data base to pass stuff back and forth.
Sounds to me like you don't know how to use GTK properly, but discussing that belongs on a GTK mailing list probably.
What I've done is declare a struct in a header file, which is included in the files for both ends. For example:
Declaring structs, typedefs, function prototypes etc yes, defining objects and function no.
-------
/* --- data.h --- */
struct data {
char question[80];
char answer[80];
} calc[80];
-------
Here you are not merely defining the struct, you are also defining an object called calc which is an array of structs.
This works fine. My question is this: Is this legal and conforming?
No, absolutely not. Any object that you use must be defined EXACTLY once, and because data.h is included in more than one source file any objects it defines are defined multiple times.
You want something like: /* --- data.h --- */ #define CALC_SIZE 80
struct data {
char question[80];
char answer[80];
};
extern struct data calc[CALC_SIZE];Then, in EXACTLY one C source file (not header) which includes data.h you have
struct data calc[CALC_SIZE];
I get from K&R2, page 82, that functions can indeed be declared in header files. Do I understand this correctly?
Yes, but only if you understand the difference between a declaration (which says basically this thing exists somewhere, but I'm not defining it here) and a definition (which says OK, this is the actual object/function right here so allocate the space/put the code here).
You need to read up on these topics, look up declaration and definition in K&R2 and learn what the two terms mean before you go any further.
Because if I do, then I'm ready to start building this application keeping the C and the Gtk completely separate.
Yes, keeping your system dependant code (in this case code dealing with GTK) isolated is a good idea.
> And I sure don't want to
start this project on the basis of UB or IDB.
This is also a good idea, and certainly something we can help with. -- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it. .
- Follow-Ups:
- Re: Newbie question
- From: Longfellow
- Re: Newbie question
- From: Longfellow
- Re: Newbie question
- References:
- Newbie question
- From: Longfellow
- Newbie question
- Prev by Date: Re: Dumb Question.
- Next by Date: Re: about C
- Previous by thread: Re: Newbie question
- Next by thread: Re: Newbie question
- Index(es):