// Sting for the Name
extern const PROGMEM char name[];
//Data structure of the Heap
typedef struct
{
AllocStrategies strategy;
uint16_t size;
MemAddr start;
MemDriver* driver;
const PROGMEM char name[];
}Heap;
expected '=', ',', ';', 'asm' or '__ attribute__' before 'char'
Why do i get this error message twice?
You forgot to include a file:
#include <avr/pgmspace.h>
The PROGMEM attribute that allows you to allocate a const variable in program space is defined there.
You are getting this error message twice because you are using PROGMEM twice.
Related
Why I can't declare this type?
typedef unsigned int8_t UINT8
Compiler error:
error: expected '=', ',', ';', 'asm' or '__attribute__' before UINT8
So here's the code from the start to the lines my errors appear. I checked more than once every pointer relation and sintax rules, but for the last three lines the complier says:
"Expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
What's wrong/missing?
Code:
typedef char labeltype;
typedef struct celltag{
labeltype label;
struct celltag* leftchild;
struct celltag* rightchild;
}celltype;
typedef celltype* BiTree;
typedef celltype* node;
node LAMBDA;
LAMBDA->label='A';
LAMBDA->leftchild=NULL;
LAMBDA->rightchild=NULL;
You don't have any functions in your code, and Instructions can only appear in functions.
The following lines are Instructions, which must be in a function:
LAMBDA->label='A';
LAMBDA->leftchild=NULL;
LAMBDA->rightchild=NULL;
I recommend putting these instructions into a main function:
typedef char labeltype;
typedef struct celltag{
labeltype label;
struct celltag* leftchild;
struct celltag* rightchild;
}celltype;
typedef celltype* BiTree;
typedef celltype* node;
int main(void) /* This is where a function starts */
{
node LAMBDA;
printf("Program Start\n");
LAMBDA->label='A';
LAMBDA->leftchild=NULL;
LAMBDA->rightchild=NULL;
printf("Program End\n");
return 0;
} /* This is the end of the function */
In C language all executable code is written inside functions. You can't just write statements in the middle of the file.
At file level in C you can only write declarations. Everything in your code are declarations, until you get to the last three lines. The last three lines are not declarations. You can't write them at file level.
I am trying to assign values to an array within a typedef struct and continually am getting an syntax error.
Error expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
Here is my code:
myfile.h
#define Digit12 0x00u
#define Digit34 0x01u
#define Digit56 0x01u
typedef struct
{
uint8_t trData[3];
} CImageVersion;
myfile.c
CImageVersion oImageVersion; // declare an instance
oImageVersion.trData = { Digit12, Digit34, Digit56};
Later on in the code
otherfile.c
extern CImageVersion oImageVersion;
An arry is a pointer but if i change the assignment to
oImageVersion->trData = { Digit12, Digit34, Digit56};
I get the same error. I am very confused as to what I am doing wrong The error is pointing to directly after the oImageVersion when I assign the values
You can't assign directly to an array. The syntax you're using is only valid when a variable is defined. I.e. you can do this:
CImageVersion oImageVersion = { { Digit12, Digit34, Digit56} };
But not this:
CImageVersion oImageVersion;
oImageVersion.trData = { Digit12, Digit34, Digit56};
If you don't assign the values when the variable is defined, you need to assign to each array element individually:
oImageVersion.trData[0] = Digit12;
oImageVersion.trData[1] = Digit34;
oImageVersion.trData[2] = Digit56;
This question already has answers here:
Are members of a structure allowed to be static ?
(5 answers)
Closed 4 years ago.
I am setting up a structure for Modbus RTU communication, but i got problems writing the apropriate structure. Here is the structure i got up to now:
#include "stdint.h"
typedef struct TModbusFrameRtu_tag
{
static const uint32_t Start : 28;
uint8_t Address;
uint8_t Function;
uint8_t Data;
uint16_t Crc16;
static const uint32_t End : 28;
}TModbusFrameRtu;
const uint32_t TModbusFrameRtu_tag::Start = 0x0000;
const uint32_t TModbusFrameRtu_tag::End = 0x0000;
But the compiler doesnt like the static const combination. Trying to compile this code the compiler prints
error: expected specifier-qualifier-list before 'static'|
error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token|
error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token|
error: expected identifier before numeric constant|
error: unknown type name 'TModbusFrameRtu'|
I thought i could save some space by declaring the Start and End member static, as they are always going to be the same and will never change for any message that is going to be send. Is this not possible in that combination or how can i solve this?
No, that's not possible.
It doesn't make sense, the members of a struct need to be together in memory, but you somehow want to "pull out" a couple of fields and have them live elsewhere.
Would you expect e.g.
TModbusFrameRtu frame_a, frame_b; // two instances
to have the same value for &frame_a.Start and &frame_b.Start? That's not how things work, at all.
The solution is probably to not include these in the structure at all, but instead make them ordinary constants inside the implementation.
Im working on a PIC24f microcontroller, writing a C code for communication protocol.Im facing an error in function Reade2PW. I thought uint16_t gives the problem so i changed the
"uint16_t" to "int16" & "int16_t" and compiled but the problem is still remains the same i.e it gives the same error. My MPLAB using XC16
compiler. I read XC16 user guide, it can support uint16_t and int16_t.
Here is the screenclip from the XC16 user guide.
How to solve this problem? Your valuable suggestions will be highly appreciated.
Thanks
#include<stdio.h>
#include <stdint.h>
int main(void)
{
..
..
return 0;
}
unsigned uint16_t Reade2PW(unsigned uint16_t rde2pw) //Error here
{
unsigned uint16_t EEPVal;
unsigned char i, *Ptr;
....
}
void SaveE2PW(unsigned uint16_t rde2pw, unsigned uint16_t Cx)//Error here
{
unsigned char i, *Ptr;
..
}
Error Description:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Reade2PW'
error: expected ';', ',' or ')' before 'rde2pw'
You have duplicate type specifiers in both your functions:
unsigned uint16_t Reade2PW(unsigned uint16_t rde2pw) //Error here
^^duplicate types here ^^ and here
Remove one. The uint16_t is already unsigned (so the u prefix). So just remove the unsigned from them:
uint16_t Reade2PW(uint16_t rde2pw)
{
uint16_t EEPVal;
// ....
}