Hot!XC32 - assignment to members of struct inside an array -

Author
Brane2
Junior Member
  • Total Posts : 116
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
2018/05/16 10:36:00 (permalink)
0

XC32 - assignment to members of struct inside an array -

Suppose I do :
 
typedef struct{
int a;
int b;
} something;

something my_arr[2];
my_arr[1].a = 3;

 
 
XC32 fails here with :
error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token

 
How do you do that in in this C89 variant ?
 
Vanilla gcc also compiles this stuff without a hitch with -std=c89...
 
 
 
 
 
#1

11 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2578
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 10:45:23 (permalink)
    0
    my_arr[1].a = 3;

    Is that inside a func. such as main() ?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 10:51:57 (permalink)
    0
    If that code doesn't compile in C89 mode, the problem is in the code you haven't shown.
    #3
    Brane2
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2011/09/29 19:56:29
    • Location: Ljubljana, Slovenia
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 10:54:35 (permalink)
    0
    Gort2015
    my_arr[1].a = 3;

    Is that inside a func. such as main() ?




     
    I tried both. Both fail the same way.
     
     
     
    #4
    Brane2
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2011/09/29 19:56:29
    • Location: Ljubljana, Slovenia
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 10:57:32 (permalink)
    0
    [/code]
    jtemples
    If that code doesn't compile in C89 mode, the problem is in the code you haven't shown.




    Well, I opened made new empty project with PIC32MK, opened inside new C file, and tried again ( deleted bunch of boilerplate comments):
     
     
     
    [code]typedef struct {
        int a;
        int b;   
    } some;
     
    int main () {
    some     my_arr[2];

    some * ptr = &(my_arr[1]);
    ptr->a = 2;
    my_arr[1].a = 3;
    return 0;
    }
     
     
    #5
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:00:22 (permalink)
    0
    Missing semicolon on return statement...
    #6
    Brane2
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2011/09/29 19:56:29
    • Location: Ljubljana, Slovenia
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:00:36 (permalink)
    0
    Edit; now it compiles.
     
    I forgot an semicolon at return.
     
    What gives ?
    Why it can be used only inside a function ?
    Some linker or environment issues ?
     
    #7
    Brane2
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2011/09/29 19:56:29
    • Location: Ljubljana, Slovenia
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:03:33 (permalink)
    0
    And why is error code so weird ?
     
    Why it complains about the syntax, when the issue is clearly eslewhere?
     
    BTW: has anyone tried to use unmodified with such  micro/interAptiv MIPS cores ?
    #8
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:04:29 (permalink)
    0
    Assignment statements cannot appear at file scope in any version of C.
    #9
    Brane2
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2011/09/29 19:56:29
    • Location: Ljubljana, Slovenia
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:05:39 (permalink)
    +1 (1)
    Hmm, forgot that. It' obvious why pink: pink
    #10
    du00000001
    Just Some Member
    • Total Posts : 1874
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 11:26:17 (permalink)
    0
    You CAN initialize some variable outside a function, but then in the style 
    some my_arr[2] = { { 1, 2 }, {3, 4} };

    Then you'll only have to find out how this initializes Smile
    (OK - the inner curlies bracket the a, b pairs for each array element, the outer ones "the whole garbage".)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2578
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC32 - assignment to members of struct inside an array - 2018/05/16 13:32:36 (permalink)
    0
    Proceed type names with, " _t".
    some_t
    Now you know that it is a type.
     
    If a structure use a cap. although not necessary.
    Some_t

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    Jump to:
    © 2018 APG vNext Commercial Version 4.5