Array - Debug error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Array - Debug error

372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Fri Feb 08 05:42:55 MST 2013
Hi all,

I try a simple program with array:

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

[B]uint8_t pole[5];[/B]

int main(void) {

// TODO: insert code here

[B]pole = {1,2,3,4,5}; // [COLOR=Red][B]<- IS IT CORRECT?[/B][/COLOR][/B]

// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
while(1) {
i++ ;
}
return 0 ;
}


When I start DEBUG so it write me:

Quote:

make all
make: Nothing to be done for `all'.

13:33:47 Build Finished (took 468ms)

13:33:48 **** Incremental Build of configuration Debug for project test ****
make all
Building file: ../src/main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC17xx -I"U:\LPCXpresso\CMSISv2p00_LPC17xx\inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"src/main.d" -MT"src/main.d" -o "src/main.o" "../src/main.c"
[COLOR=Red]../src/main.c: In function 'main':
../src/main.c:33:9: error: expected expression before '{' token
make: *** [src/main.o] Error 1
[/COLOR]
13:33:49 Build Finished (took 968ms)



What do I do wrong?
0 Kudos
8 Replies

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sun Feb 10 06:29:08 MST 2013
Thank you for your ideas ;)
0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Sat Feb 09 10:56:13 MST 2013
While the memcpy() is probably as close as you'll get I have a sneaking suspicion that the slightly obvious
pole[0] = 1;
pole[1] = 2;
pole[2] = 3;
pole[3] = 4;
pole[4] = 5;

May actually be the "tightest" solution on this occasion. Either that or:
for (uint8_t i=0; i<5; i++) pole = i+1;

Though that only works because of the pattern to the example data.
0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Fri Feb 08 12:52:24 MST 2013
[FONT=Comic Sans MS][SIZE=1]My mistake (sorry). I must have read the first post and skipped to the end.
I hate it when I assume and it bites me!

[/SIZE][/FONT]
0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Fri Feb 08 11:24:39 MST 2013

Quote: MikeSimmonds
[FONT=Arial][SIZE=1]

The {1,2,...} are array [I]initialisers[/I], and can only be used in the [I]declaration[/I].

use
 uint8 pole[5] = {1,2,3,4,5};
and lose the 'pole =' in main.

Mike

[/SIZE][/FONT]



:confused: That's exactly what OP doesn't want


Quote: masterboy
I know this way, but I want to save data to "pole" in MAIN(). Is it possible?

0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Fri Feb 08 09:53:59 MST 2013
[FONT=Arial][SIZE=1]
Quote: masterboy
Hi all,

I try a simple program with array:

[/SIZE][/FONT]
Quote: masterboy
[FONT=Arial][SIZE=1]

[/SIZE][/FONT]
 [FONT=Arial][SIZE=1]
[/SIZE][/FONT][FONT=Arial][SIZE=1][B]uint8_t pole[5];[/B][/SIZE][/FONT]  [FONT=Arial][SIZE=1]

int main(void) {[/SIZE][/FONT] [FONT=Arial][SIZE=1]
  [/SIZE][/FONT][FONT=Arial][SIZE=1]    [B]pole = {1,2,3,4,5}; // [COLOR=Red][B]<- IS IT CORRECT?[/B][/COLOR][/B]
[/SIZE][/FONT][FONT=Arial][SIZE=1]}[/SIZE][/FONT]
[FONT=Arial][SIZE=1]When I start DEBUG so it write me:


What do I do wrong? [/SIZE][/FONT]  [FONT=Arial][SIZE=1]:([/SIZE][/FONT]

[FONT=Arial][SIZE=1]

The {1,2,...} are array [I]initialisers[/I], and can only be used in the [I]declaration[/I].

use
 uint8 pole[5] = {1,2,3,4,5};
and lose the 'pole =' in main.

Mike

[/SIZE][/FONT]
0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 08 06:25:05 MST 2013

Quote: masterboy
I know this way, but I want to save data to "pole" in MAIN(). Is it possible?



Everything is possible

uint8_t pole[5];

int main(void) {
    
    // TODO: insert code here

    // Enter an infinite loop, just incrementing a counter
    volatile static int i = 0 ;
  [COLOR=Red]  memcpy(&pole[0],(uint8_t*)"\001\002\003\004\005",5);[/COLOR]
    while(1) {
        i++ ;
    }
    return 0 ;
}

0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Fri Feb 08 05:53:24 MST 2013
I know this way, but I want to save data to "pole" in MAIN(). Is it possible?
0 Kudos

350 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 08 05:51:47 MST 2013
uint8_t pole[5]  = {1,2,3,4,5};
Google is your friend :eek:

http://stackoverflow.com/questions/201101/how-to-initialize-an-array-in-c
0 Kudos