Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

about niosII

Hi,

I write in NiosII this instruction

int a,b;

int r;

a=4;

b=98;

r=a&&b;

the problem i have a message error ,when i use && ,I don't know why ?

can sameone help me to use this commande && ?

thank you

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The sintax is correct.

    What's the compiler error message?

    PS: I'd recommend spaces to separate && symbol (logical AND); although this is not mandatory, it will improve code readability.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i try with espace but i have the some error

    this a part of code of erode

    int **IM ,**im1;

    unsigned char r,u,ml,mm,mr,d;

    for(int i=1;i<height-1;i++){

    for(int j=1;j<width-1;j++)

    {

    u = im1[i-1][j];

    ml = im1[j-1];

    mm = im1[j];

    mr = im1[j+1];

    d = im1[i+1][j];

    r= (u && d) && (ml && mr && mm);

    im[j]=r

    }}

    this code turn witn succes under visual c++ but under nios II a i have this error: expected unqualified-id before

    processeur failed
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    for(int i=1;i<height-1;i++){

    for(int j=1;j<width-1;j++)

    --- Quote End ---

    You can't define variables inside the for loop instruction.

    This mode is not supported by Nios C compiler.

    Declare i and j with other variables.

    --- Quote Start ---

    int **IM ,**im1;

    --- Quote End ---

    IMHO this declaration is ambiguous if you then use these pointers to address a bidimensional array.

    You don't specify dimensions, so, how can compiler know how to map array indexes to memory?

    --- Quote Start ---

    IM[i][j]=r

    --- Quote End ---

    Semicolon missing

    Regards

    Cris
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    defining variables in for loops is legal in C++, but not in C. Visual isn't a 100% compliant C compiler and sometimes lets you do non standard things ;)

    The biggest problem with this code is that you use the IM and im1 pointers without assigning them a proper value first. This will probably crash in most cases.

    You should define static arrays instead.