Re: Problems dereferensing my C structures (custom types)
From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 02/17/04
- Next message: nrk: "Re: Problem with pointer to array of structures"
- Previous message: Timo: "Problem with pointer to array of structures"
- In reply to: Franz: "Problems dereferensing my C structures (custom types)"
- Next in thread: CBFalconer: "Re: Problems dereferensing my C structures (custom types)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 17 Feb 2004 12:24:35 GMT
fstruwig@msn.com (Franz) wrote:
> typedef struct _tbl_certificate{
> int cert_id;
> char *cert_name;
> }tbl_certificate;
Two notes:
* identifier names starting with _ are reserved for use by the
implementation, at file scope. This declaration probably is at file
scope. Therefore, _tbl_certificate is not a legal name for that struct.
Besides, it is perfectly legal to have a struct tbl_certificate,
typedef'ed to tbl_certificate; struct names are in a different namespace
from normal identifiers.
* some people would advise you not to use typedef in this situation at
all. You only gain a couple of keystrokes, and you lose transparence.
OTOH, you gain some data hiding, which may be good in some
circumstances.
So declare this as
typedef struct tbl_certificate {
int cert_id;
char *cert_name;
} tbl_certificate;
or even simply as
struct tbl_certificate {
int cert_id;
char *cert_name;
};
(Identifiers beginning with __ or _ and a capital letter are reserved
for the implementation regardless of scope, btw. I find it more
practical never to start a name with _ anyway, and never mind where it
happens to be allowed.)
> typedef struct _cameraObj{
> tbl_camera camera;
> tbl_certificate *certificate;
> }cameraObj;
Ditto here, of course.
> I am having trouble accessing the certificate array in the cameraObj struct.
>
> eg. cameraObj *camera;
> camera->certificate[0].cert_id = 7;
>
> This doesn't want to work. Any suggestions or ideas would be greatly appreciated!
Well, the error is not in what you posted - that part is OK, except for
the underscore. Presumably, the error is in the part of your code you
did not post; or perhaps it is in the part that you didn't even write,
but should have. You did remember to allocate memory for all those
pointers to point at, did you?
If you need more help, you'll have to help us help you. Describe exactly
what goes wrong; "this doesn't work" is an error report I expect from my
users, not from a fellow programmer. Whittle down your code to the
smallest example that demonstrates the problem, but is still compilable,
and post that.
Richard
- Next message: nrk: "Re: Problem with pointer to array of structures"
- Previous message: Timo: "Problem with pointer to array of structures"
- In reply to: Franz: "Problems dereferensing my C structures (custom types)"
- Next in thread: CBFalconer: "Re: Problems dereferensing my C structures (custom types)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|