struct problem, please help 
Author Message
 struct problem, please help

Quote:

> I would be grateful if someone could e-mail me a tip for the following
>problem. The header file contains:
>typedef struct rgb_mix
>    {
>    unsigned char red;
>    unsigned char green;
>    unsigned char blue;
>    } RGB_MIX;
>The source file contains:
>RGB_MIX black;
>black.red = 0;
>black.green = 0;
>black.blue = 0;
>The compiler bites me on the last 3 lines by saying "type mismatch in
>redeclaration of 'black'".  What doesn't it like?  (Note; have tried
>explicitly typecasting the 0 as an unsigned char, it doesn't help).

Hi Jon---I have a feeling that somewhere there may be something already
named ``black'' (and I would also not be surprised if there was ``white'').

Best regards,
Derick.
--
+-----------------------------------------------------------------------------+
| Derick R. Qua-Gonzalez                                           | ________ |
| Department of High Energy Physics, California State University   | \      / |

|        ``It is better to be hated for what one is,               |   \  /   |
|          than loved for what one is not.'' (A. Gide)             | G  \/ USA|
+------------------------------------------------------------------+----------+
| mQBNAy/qJJMAAAECANBCB543eTUkdG8Mqx6K2cm3WxCVtKY8ZbB9WY6A2Ne4dQi8 | PGP2.6.2 |
| xh7OxjHXP/eXp5BSbmVAihEGd7r+5g/yknko56kABRG0MERKUiBRdWEtR29uemFs |  Public  |
| ZXogPGRxdWFAUHJvbWV0aGV1cy5FYXJ0aGxpbmsuTmV0Pg==                 | KeyBlock |
| =70DW                                                            | 06.20.95 |
+------------------------------------------------------------------+----------+



Tue, 27 Jan 1998 03:00:00 GMT  
 struct problem, please help
 I would be grateful if someone could e-mail me a tip for the following
problem.

The header file contains:

typedef struct rgb_mix
        {
        unsigned char red;
        unsigned char green;
        unsigned char blue;
        } RGB_MIX;

The source file contains:

RGB_MIX black;
black.red = 0;
black.green = 0;
black.blue = 0;

The compiler bites me on the last 3 lines by saying "type mismatch in
redeclaration of 'black'".  What doesn't it like?  (Note; have tried
explicitly typecasting the 0 as an unsigned char, it doesn't help).

                                        Thanks in advance,
                                                Jon.



Tue, 27 Jan 1998 03:00:00 GMT  
 struct problem, please help
|> I would be grateful if someone could e-mail me a tip for the following
|> problem.
|>
|> The header file contains:
|>
|> typedef struct rgb_mix
|>   {
|>   unsigned char red;
|>   unsigned char green;
|>   unsigned char blue;
|>   } RGB_MIX;
|>
|> The source file contains:
|>
|> RGB_MIX black;
|> black.red = 0;
|> black.green = 0;
|> black.blue = 0;
|>
|> The compiler bites me on the last 3 lines by saying "type mismatch in
|> redeclaration of 'black'".  What doesn't it like?  (Note; have tried
|> explicitly typecasting the 0 as an unsigned char, it doesn't help).

You didn't say if the source file included the header file...Assigning
an int to an unsigned char should at most give a warning. It's
complaining about your variable 'black' because it must not really
understand what an RGB_MIX is. At least that's how I see it...
--
"Avoid computer viruses -- practice safe hex!"




Tue, 27 Jan 1998 03:00:00 GMT  
 struct problem, please help

Quote:
> I would be grateful if someone could e-mail me a tip for the following
>problem.

>The header file contains:

>typedef struct rgb_mix
>    {
>    unsigned char red;
>    unsigned char green;
>    unsigned char blue;
>    } RGB_MIX;

>The source file contains:

>RGB_MIX black;
>black.red = 0;
>black.green = 0;
>black.blue = 0;

If all of the above is outside of all functions (including main) then it
is an example of incorrect initialization.  Use the following instead:

RGB_MIX black = {0, 0, 0};


- Show quoted text -

Quote:

>The compiler bites me on the last 3 lines by saying "type mismatch in
>redeclaration of 'black'".  What doesn't it like?  (Note; have tried
>explicitly typecasting the 0 as an unsigned char, it doesn't help).

>                                    Thanks in advance,
>                                            Jon.



Tue, 27 Jan 1998 03:00:00 GMT  
 struct problem, please help

Quote:

>The header file contains:
>typedef struct rgb_mix
>        {
>        unsigned char red;
>        unsigned char green;
>        unsigned char blue;
>        } RGB_MIX;
>The source file contains:
>RGB_MIX black;
>black.red = 0;
>black.green = 0;
>black.blue = 0;
>The compiler bites me on the last 3 lines by saying "type mismatch in
>redeclaration of 'black'".  What doesn't it like?  (Note; have tried
>explicitly typecasting the 0 as an unsigned char, it doesn't help).

There is nothing wrong ( when I surround your source code with
"int main {" and "return 0; }").  If you are trying to do the
assignments outside of an executable block as an initialization, then
you need to open your C book and read up on "initializing a struct
object."
--

* Chicago, IL (USA)    


Wed, 28 Jan 1998 03:00:00 GMT  
 struct problem, please help

Juniman)says...
Quote:

> I would be grateful if someone could e-mail me a tip for the following
>problem.

>The header file contains:

>typedef struct rgb_mix
>        {
>        unsigned char red;
>        unsigned char green;
>        unsigned char blue;
>        } RGB_MIX;

>The source file contains:

>RGB_MIX black;
>black.red = 0;
>black.green = 0;
>black.blue = 0;

There are at least two ways to fix this.

1) The last three lines should be in a function e.g.

RGB_MIX black;
int main(void)
{
black.red = 0;
black.green = 0;
black.blue = 0;

Quote:
}

2) You gan get rid of the last three lines be declaring black as

RGB_MIX black = { 0, 0, 0 };

hope that is useful.
--
MAG
/* ********************************************************
To understand recursion one must first understand recursion
******************************************************** */



Wed, 28 Jan 1998 03:00:00 GMT  
 struct problem, please help

Quote:


>Juniman)says...

>> I would be grateful if someone could e-mail me a tip for the following
>>problem.

>>The header file contains:

>>typedef struct rgb_mix
>>        {
>>        unsigned char red;
>>        unsigned char green;
>>        unsigned char blue;
>>        } RGB_MIX;

>>The source file contains:

>>RGB_MIX black;

I _think_ that you want to use 'rgb_mix' here, not 'RGB_MIX'

Quote:
>>black.red = 0;
>>black.green = 0;
>>black.blue = 0;

I'm not 100% sure, but i belive that your definition says that we hace
a structure called 'rgb_mix' and a variable of that type called
'RGB_MIX'

Anyway, Good Luck
Jarrod S Lowe



Sun, 01 Feb 1998 03:00:00 GMT  
 struct problem, please help


Quote:
>>>The header file contains:
>>>typedef struct rgb_mix
>>>        {
>>>        unsigned char red;
>>>        unsigned char green;
>>>        unsigned char blue;
>>>        } RGB_MIX;

>>>The source file contains:

>>>RGB_MIX black;
>I _think_ that you want to use 'rgb_mix' here, not 'RGB_MIX'

No.  rgb_mix is only the tag for the struct, by itself it is not
even a type.

Quote:
>I'm not 100% sure, but i belive that your definition says that we hace
>a structure called 'rgb_mix' and a variable of that type called
>'RGB_MIX'

You're incorrect.  The typedef created a new type 'RDB_MIX' that
is equivilent to 'struct rgb_mix'.

I don't have any idea why the original does not work, as it looks
fine to me.




Sun, 01 Feb 1998 03:00:00 GMT  
 struct problem, please help


Quote:


(Jonathan
> >Juniman)says...

> >> I would be grateful if someone could e-mail me a tip for the following
> >>problem.

> >>The header file contains:

> >>typedef struct rgb_mix
> >>        {
> >>        unsigned char red;
> >>        unsigned char green;
> >>        unsigned char blue;
> >>        } RGB_MIX;

> >>The source file contains:

> >>RGB_MIX black;
> I _think_ that you want to use 'rgb_mix' here, not 'RGB_MIX'

If you don't mind another opinion, he's right to use RGB_MIX because that
is the type, to use rgb_mix you would have to write "struct rgb_mix" which
is not very nice.
Quote:
> >>black.red = 0;
> >>black.green = 0;
> >>black.blue = 0;

You don't say what error messages you get, but your compiler may be strict
about types; try casting these i.e. black.red = (unsigned char)0;
Quote:

> I'm not 100% sure, but i belive that your definition says that we hace
> a structure called 'rgb_mix' and a variable of that type called
> 'RGB_MIX'

No the type is RGB_MIX, the sructure tag is rgb_mix and the type is black.

Hope this helps

David Masters
AUP
Paris



Thu, 05 Feb 1998 03:00:00 GMT  
 struct problem, please help

Quote:


>> >>The header file contains:

>> >>typedef struct rgb_mix
>> >>        {
>> >>        unsigned char red;
>> >>        unsigned char green;
>> >>        unsigned char blue;
>> >>        } RGB_MIX;

>> >>The source file contains:

>> >>RGB_MIX black;
>> I'm not 100% sure, but i belive that your definition says that we hace
>> a structure called 'rgb_mix' and a variable of that type called
>> 'RGB_MIX'
>No the type is RGB_MIX, the sructure tag is rgb_mix and the type is black.

>Hope this helps

Well, maybe the type is black and the variable name is RGB_MIX, but then
the language you are talking about is not C.

Kurt
--
| Kurt Watzka                             Phone : +49-89-2180-6254




Fri, 06 Feb 1998 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. about struct problem!Please help me!

2. about struct problem!Please help me!

3. New2C: Problems understanding STRUCT Please HELP!!!!

4. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

5. Please help!!!!Please help!!!!Please help!!!!

6. Pointer to struct function NEWBIE PLEASE HELP

7. Struct memory layout, please help!

8. Pointer to a struct within an array Help Please

9. struct help please..

10. Struct Newbie!! Help please

11. Struct.....Help Please!!

12. Please help me with Pointers and Structs

 

 
Powered by phpBB® Forum Software