Ask Experts Questions for FREE Help !
Ask
    emorrp1's Avatar
    emorrp1 Posts: 2, Reputation: 1
    New Member
     
    #1

    Jun 24, 2008, 07:17 AM
    Struct member assignment (c-only)
    Hi, I'm now in a job where I have to code in pure C (not C++) and am having trouble adjusting to the differences, hope you can help. As soon as I un-comment any one of the commented lines in the code snippet below, the program fails to compile with a syntax error on the "int a=0..." line after the commented block (This line isn't a problem while the rest is commented out). I haven't been able to identify the problem, even after searching the internet, am I missing something about the assignment operator/structs/arrays in C?

    [CODE=c]
    typedef struct touch_switch {
    int p_loc;
    } touch_switch_t;

    void touch_switches_set(touch_switch_t *switches[]);



    void main(void) {
    touch_switch_t S[8];

    /* S[0].p_loc = 0x0;
    S[1].p_loc = 0x1;
    S[2].p_loc = 0x4;
    S[3].p_loc = 0x5;
    S[4].p_loc = 0x2;
    S[5].p_loc = 0x3;
    S[6].p_loc = 0x8;
    S[7].p_loc = 0x9;*/
    /* touch_switches_set(&S);*/

    int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
    }

    void touch_switches_set(touch_switch_t *switches[]) {
    (*switches)[0].p_loc = 0x0;
    (*switches)[1].p_loc = 0x1;
    (*switches)[2].p_loc = 0x4;
    (*switches)[3].p_loc = 0x5;
    (*switches)[4].p_loc = 0x2;
    (*switches)[5].p_loc = 0x3;
    (*switches)[6].p_loc = 0x8;
    (*switches)[7].p_loc = 0x9;
    }
    [/CODE]
    emorrp1's Avatar
    emorrp1 Posts: 2, Reputation: 1
    New Member
     
    #2

    Jun 24, 2008, 08:54 AM
    The solution (from another board) is:

    "The reason you get an error on the int a ... is that you are not defining your variables before the start of code. In C++ you can literally put a variable definition anywhere any statement can go. Some C compilers allow this too, but far from all. So as soon as you start writing code statements (anything that isn't a type, function or variable declaration/definition), you can not declare any further variables in that block.

    Your function prototype is also missing a () set. "

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Assignment Help [ 5 Answers ]

Hi, I'm currently studying Forensic Science at College in England, and I was wondering if you could give me some pointers on an assignment I have as we have had very little guidance on it. The task is to review the types of energy (I believe this means kinetic, potential etc.), their...

The Assignment ? [ 1 Answers ]

Another movie which I saw in my teens and would like to revisit was something about 3 people who have esp abilities. The title which crops up is "The Assignment" but I'm not really sure. These 3 people were sent on a mission and they use esp to complete the job. Thanks.

Assignment [ 1 Answers ]

Hi I have this english assignment and I need to know a law about make-up I'm not so sure if there is one but maybe some of the other members could clarrify this My question really is there any legal limits on make-up? Thank you if you reply I'm hoping for an A+:)


View more questions Search