help with Xcode

Sep 22, 2014 4 Replies

note: im writeing a OS my compile claims this code faulty:



typedef char* string; typedef string* screen; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long long uint64_t; typedef int size_t; typedef struct pixel {


Is "pixel" defined anywhere else?

Mike Perkins Video Solutions Ltd www.videosolutions.ltd.uk

Don't you *really* want:

typedef struct { uint8_t R; uint8_t G; uint8_t B; } pixel_t;

Also, consider if you want to adopt some form of convention for your type identifiers. E.g., type_t, Type, or something else. I find this especially handy when documenting code.

For example, if I say "screen_t", then I am referring to a datatype (that, perhaps, describes the contents of a "real" screen). If, instead, the data type and the "object" that it represents share the same name, then you have no easy way of indicating which you are talking/writing about.

This code is erroneous; not because anything is being "redefined" but because you don't give a name after the type. It should be e.g.:

struct pixel { uint8_t R; uint8_t G; uint8_t B; };

or:

typedef struct { uint8_t R; uint8_t G; uint8_t B; } pixel_t;

or:

typedef struct pixel { uint8_t R; uint8_t G; uint8_t B; } pixel_t;

or:

struct pixel { uint8_t R; uint8_t G; uint8_t B; };

typedef struct pixel pixel_t;

The first option allows you to write declarations as "struct pixel p;", the second as "pixel_t p;", the last two using either form.

Here, "pixel" is a struct tag while "pixel_t" is a typedef. They exist in separate namespaces. A struct tag can only appear following the "struct" keyword, i.e. as "struct pixel".

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required