Shop OBEX P1 Docs P2 Docs Learn Events
Issue with C syntax — Parallax Forums

Issue with C syntax

Ray0665Ray0665 Posts: 231
edited 2014-12-23 13:30 in General Discussion
Im getting a syntax warning I dont understand
can anyone help ?

I made the follow in declarations in C

#define stx 0x02
unsigned int GetByte() {int x; read (usbPort, &x, sizeof(x) ); return x; }

and I am getting the following warnings which I do not understand

warning: comparison between pointer and integer [enabled by default]
do while (GetByte != stx) {}
^
error: expected ‘while’ before ‘N’
N = GetByte;

And later in the program I get this:
warning: assignment makes integer from pointer without a cast [enabled by default]
Ck2 = GetByte;
where Ck2 is declared as
unsigned short int N, Ck1, Ck2;

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2014-12-23 13:11
    Ray0665 wrote: »
    Im getting a syntax warning I dont understand
    can anyone help ?

    I made the follow in declarations in C

    #define stx 0x02
    unsigned int GetByte() {int x; read (usbPort, &x, sizeof(x) ); return x; }

    and I am getting the following warnings which I do not understand

    warning: comparison between pointer and integer [enabled by default]
    do while (GetByte != stx) {}
    ^
    error: expected ‘while’ before ‘N’
    N = GetByte;

    And later in the program I get this:
    warning: assignment makes integer from pointer without a cast [enabled by default]
    Ck2 = GetByte;
    where Ck2 is declared as
    unsigned short int N, Ck1, Ck2;
    You need to include parens in a call to a C function. Also, you have the incorrect syntax for while. Try something like this:
    while (GetByte() != stx) {}
    
    Also, your GetByte function is not going to do what you expect since you've declared x to be an int which is four bytes wide (32 bits) on the Propeller. You probably want to declare x to be of type char. The function, as you've written it, will try to read four bytes not one byte.
  • Ray0665Ray0665 Posts: 231
    edited 2014-12-23 13:30
    Thanks David I guess Ive been a spin propeller head for too long my C skills which were never that great are now almost gone.
    You have cleared all the issues now I just have to remember it..
Sign In or Register to comment.