Re: assigning values to a struct
From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 08/26/04
- Next message: Karthik: "compiling a library with a c code"
- Previous message: Eric Sosman: "Re: generating strings"
- In reply to: Chris Hiler: "assigning values to a struct"
- Next in thread: Jack Klein: "Re: assigning values to a struct"
- Reply: Jack Klein: "Re: assigning values to a struct"
- Reply: Old Wolf: "Re: assigning values to a struct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Aug 2004 14:30:43 -0400
Chris Hiler wrote:
> Why isn't it possible to assign a value to a struct at run time?
>
> In my header file I have something like this:
>
> typedef struct SomeStruct_t
> {
> int Member1;
> int Member2;
> int Member3;
> };
>
>
> then in main.c I declare somthing like this:
>
> struct SomeStruct_t ExampleStructure;
>
>
> Then in main all I want to do is this:
>
> void main(void)
> {
> ExampleStructure.Member1 = 1;
>
> }
>
>
> My compiler tells me that '=' is an incompatible operator. It might
> help to know that I'm using a keil 8051 C compiler, and it isn't
> totally ANSI-C compliant.
Big deal. It is your useless 'typedef' that is the problem:
/* mha: The original typedef was comletely senseless. It provided no
new type name. An analogous typedef would be 'typedef int;'. I
have remove the useless keyword 'typedef', since the attempted use
doesn't need it. */
struct SomeStruct_t
{
int Member1;
int Member2;
int Member3;
};
/* mha: The original return type for main was 'void'. This is
illegal, illiterate, and proves that the original poster has
violated civilized norms by neither following the newsgroup nor
checking the FAQ before posting. Fixed. */
int main(void)
{
struct SomeStruct_t ExampleStructure;
ExampleStructure.Member1 = 1;
return 0; /* mha: for C89 or C90 */
}
- Next message: Karthik: "compiling a library with a c code"
- Previous message: Eric Sosman: "Re: generating strings"
- In reply to: Chris Hiler: "assigning values to a struct"
- Next in thread: Jack Klein: "Re: assigning values to a struct"
- Reply: Jack Klein: "Re: assigning values to a struct"
- Reply: Old Wolf: "Re: assigning values to a struct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|