public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] using struct
@ 2001-04-27  2:51 Carlos Camargo
  2001-04-27  3:18 ` Andrew Lunn
  2001-04-27  3:21 ` Martin van Veen
  0 siblings, 2 replies; 5+ messages in thread
From: Carlos Camargo @ 2001-04-27  2:51 UTC (permalink / raw)
  To: ecos-discuss

Hi all.

A simple question:

Can I use struct in ecos?

I tried to declare a struct inside a thread:

static void stimulus( cyg_addrword_t data )
{
    int i, j;
 
   struct hola{
      int a;
    };

    hola.a = 5; // This is 54 line.
	..
	..    
    }
 
}

and i have the following error message:
sync_mbox.c:54: `hola' undeclared (first use in this
function)

Thanks

Best regards..

Carlos Camargo

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] using struct
  2001-04-27  2:51 [ECOS] using struct Carlos Camargo
@ 2001-04-27  3:18 ` Andrew Lunn
  2001-04-27  3:21 ` Martin van Veen
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2001-04-27  3:18 UTC (permalink / raw)
  To: Carlos Camargo; +Cc: eCos Disuss

On Fri, Apr 27, 2001 at 02:51:42AM -0700, Carlos Camargo wrote:
> Can I use struct in ecos?

You can use all the standard C constructs.

> I tried to declare a struct inside a thread:

Your syntax is wrong for declaring a struct. In this case hola is the
name of the structure, not the name of the variable. You now need to
use the structure to declare the variable.

I would normally do something link...

struct hola_s {
        int a;
};

struct hola_s hola;

This is a C question, not ecos, so you would be better asking
questions on a C mailing list.

        Andrew

> static void stimulus( cyg_addrword_t data )
> {
>     int i, j;
>  
>    struct hola{
>       int a;
>     };
> 
>     hola.a = 5; // This is 54 line.
> 	..
> 	..    
>     }
>  
> }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] using struct
  2001-04-27  2:51 [ECOS] using struct Carlos Camargo
  2001-04-27  3:18 ` Andrew Lunn
@ 2001-04-27  3:21 ` Martin van Veen
  1 sibling, 0 replies; 5+ messages in thread
From: Martin van Veen @ 2001-04-27  3:21 UTC (permalink / raw)
  To: Carlos Camargo; +Cc: ecos-discuss

Hi Carlos

--- Carlos Camargo <carlos_ivan_camargo@yahoo.com> wrote:
> Can I use struct in ecos?

Sure, why not...

> I tried to declare a struct inside a thread:
> 
> static void stimulus( cyg_addrword_t data )
> {
>     int i, j;
>  
>    struct hola{
>       int a;
>     };
> 
>     hola.a = 5; // This is 54 line.
> 	..
> 	..    
>     }
>  
> }
> 
> and i have the following error message:
> sync_mbox.c:54: `hola' undeclared (first use in this
> function)

You gave the struct a tag, but you didn't declare it. So therefore
the compiler complains (it has nothing to do with eCos). This will
do better, I guess:

struct
{
    int a;
} hola;

Greetings,
Martin.


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [ECOS] using struct
@ 2001-04-27  3:49 Nielsen Linus
  0 siblings, 0 replies; 5+ messages in thread
From: Nielsen Linus @ 2001-04-27  3:49 UTC (permalink / raw)
  To: ecos-discuss

...and if you read my last post, you will probably understand
that I have been too much into C++ lately.

The answer to you question is of course that in C, you cannot
leave out the keyword "struct" from your variable declaration.

You code should look like this:

   struct hola_type {
      int a;
    };

    struct hola_type hola;
    hola.a = 5; // This is 54 line.

But still, this is a C question, not eCos.

/Linus


> Hi all.
> 
> A simple question:
> 
> Can I use struct in ecos?
> 
> I tried to declare a struct inside a thread:
> 
> static void stimulus( cyg_addrword_t data )
> {
>     int i, j;
>  
>    struct hola{
>       int a;
>     };
> 
>     hola.a = 5; // This is 54 line.
> 	..
> 	..    
>     }
>  
> }
> 
> and i have the following error message:
> sync_mbox.c:54: `hola' undeclared (first use in this
> function)
> 
> Thanks
> 
> Best regards..
> 
> Carlos Camargo
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [ECOS] using struct
@ 2001-04-27  3:31 Nielsen Linus
  0 siblings, 0 replies; 5+ messages in thread
From: Nielsen Linus @ 2001-04-27  3:31 UTC (permalink / raw)
  To: ecos-discuss

> A simple question:
> 
> Can I use struct in ecos?

Yes.

> I tried to declare a struct inside a thread:
> 
> static void stimulus( cyg_addrword_t data )
> {
>     int i, j;
>  
>    struct hola{
>       int a;
>     };
> 
>     hola.a = 5; // This is 54 line.
> 	..
> 	..    
>     }
>  
> }
> 
> and i have the following error message:
> sync_mbox.c:54: `hola' undeclared (first use in this
> function)

This is a pure C issue. You have declared a struct, but you have not
delared an _instance_ of that struct. You should do it like this:

   struct {
      int a;
    } hola;

    hola.a = 5; // This is 54 line.

Notice the difference.

/Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-04-27  3:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-27  2:51 [ECOS] using struct Carlos Camargo
2001-04-27  3:18 ` Andrew Lunn
2001-04-27  3:21 ` Martin van Veen
2001-04-27  3:31 Nielsen Linus
2001-04-27  3:49 Nielsen Linus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).