Topic : C- Ride and Structures

Forum : 8051

Original Post
Post Information Post
March 17, 2007 - 4:37pm
Guest

Hello, does Ride support structs?
I tryed this code and it did not work:

#include 
#include 

struct Fonema {
char a[2];
};

void main() {
   
   Fonema letra;
   
   while(1) {
      if (P0 == 00000001) {
      strcpy(letra.a,"bla");
      }
   }
}

Could anyone answer my question or help me?
Thanks! ^^

PS: I'm coding it for the 80C51...

Replies
Post Information Post
+1
0
-1
March 18, 2007 - 1:55am
Guest

Nvm, I found what was wrong.
I went in Options,Project,RC51,Source and marked ('struct/ union/ enum' optional).
Bye!

+1
0
-1
March 19, 2007 - 9:19am
Guest

Hello,

in fact the standard ANSI C syntax does not allow the declaration of a structure the way you did it on your example. This is only allowed in C++ syntax. The standard C syntax is:

[...]

struct Fonema letra;

[...]

You could also define a new type 'Fonema' using typedef:
typedef struct {
char a[2];
} Fonema;

[...]

Fonema letra;

[...]

regards,
Lionel
+1
0
-1
March 19, 2007 - 8:05pm
Guest

lionel wrote:
Hello,

in fact the standard ANSI C syntax does not allow the declaration of a structure the way you did it on your example. This is only allowed in C++ syntax. The standard C syntax is:

[...]

struct Fonema letra;

[...]

You could also define a new type 'Fonema' using typedef:
typedef struct {
char a[2];
} Fonema;

[...]

Fonema letra;

[...]

regards,
Lionel

Thanks, but how I said before, I solucioned the problem and it worked with the code of C++, I tested my program, so I will keep using in that way ^^'
Bye! :P
+1
0
-1
March 19, 2007 - 9:08pm
Guest

in fact the standard ANSI C syntax does not allow the declaration of a structure the way you did it on your example

then

Thanks, but how I said before, I solucioned the problem and it worked with the code of C++, I tested my program, so I will keep using in that way

Then what will you do the day Raisonance realize they allow something they should not allow?

Erik

+1
0
-1
March 20, 2007 - 10:17pm
Guest

erikm wrote:
in fact the standard ANSI C syntax does not allow the declaration of a structure the way you did it on your example

then

Thanks, but how I said before, I solucioned the problem and it worked with the code of C++, I tested my program, so I will keep using in that way

Then what will you do the day Raisonance realize they allow something they should not allow?

Erik


Well, I think that they know what they are doing because there is a option on the Project Options that let you do what I did... Look:

And if they remove this I just change my structures to the C form, that's not hard to do ;D

+1
0
-1
March 21, 2007 - 2:59pm
Guest

And if they remove this I just change my structures to the C form, that's not hard to do

why not do it now?

Getting in the habit of using non-standard C can easily get you to where 'something' goes wrong for 'some' reason and THAT would be one hellacious debugging session.

No bad about Raisonance in this statement, please do not read it as such, but do you really think that the support for non-standard is the area where Raisonance spend the most verification time?

two wrongs do not make a right

Erik

+1
0
-1
March 21, 2007 - 4:19pm
Guest

erikm wrote:
And if they remove this I just change my structures to the C form, that's not hard to do
why not do it now?

Pass to the C form? How this should be? :O
Because you said above that the C structures that lionel used are not accepted in RIDE, am I right?
Bye!
+1
0
-1
March 21, 2007 - 5:05pm
Guest

Xero wrote:
Because you said above that the C structures that lionel used are not accepted in RIDE, am I right?

I don't think that's what Erik wanted to say.

We all agree that the syntax I gave is correct in C. I add now that this syntax is always valid, even if the 'struct/enum optional' option is checked. It will always work. Checking the option is a way to write code in a way some people prefer, but it is not standard C. Standard C syntax will always be valid, whatever the options status.

IMHO, Erik (correct me if I am wrong) wanted to express that the standard C syntax is preferable because it will always work, and that we may, one day or another, remove this option. For now the option is here, feel free to use it.

regards
Lionel

+1
0
-1
March 23, 2007 - 12:30am
Guest

Mmmmm, so what is the right way to use structures in standard C?

+1
0
-1
March 23, 2007 - 9:08am
Guest

This is the right way, whatever the compiler and the platform.

regards
Lionel

+1
0
-1
March 23, 2007 - 9:48pm
Guest

Ok, thanks :P
Bye!