C error: expected '=', ',', ';', - c

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;
// ....
}

Related

Motive : This code aims to provide default values to structure members inside structure defination [duplicate]

This question already has answers here:
How to initialize a struct in accordance with C programming language standards
(16 answers)
Closed 2 years ago.
Here's my code:
#include<stdio.h>
struct parent_structure
{
char pe_1 = 'a';
};
struct child_structure
{
int ce_1 = 1;
int ce_2 = 2;
int ce_3 = 3;
struct sample_structure
{
int ss_1 = 1 ;
char ss_2 = 'a';
} ce_4 ;
struct parent_structure ce_5;
};
int main()
{
struct child_structure c_1;
printf("size of element : %d",sizeof(c_1));
return 0;
}
ERROR:
test.c:5:15: error: expected ':', ',', ';', '}' or '_attribute_' before '=' token
char pe_1 = 'a';
^
test.c:10:14: error: expected ':', ',', ';', '}' or '_attribute_' before '=' token
int ce_1 = 1;
^
PROBLEMS:
* If i initalize value at the time of defining structure
it gives the error shown above.
I was trying this question for a while and if I initialize values to members of structure like at the time of declaration of structure it shows an error.
Please tell me what is wrong with this?
You cannot give default values to struct members in C. Structures are data types.
Just like the way you declare variables int a; you declare struct variables like struct child_structure c_1;.
Don't confuse struct with struct struct_name, struct itself is not a data type, therefore struct_name is not a variable, and therefore you cannot initialize it as you do.

What does "expected '=', ',', ';', 'asm' or '__attribute__' before 'char'" mean? AVR

// 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.

static const struct member [duplicate]

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.

error (dcc:1086):redeclaration of uint16_t

There is a header file in my project that contains this line:
typedef unsigned short uint16_t;
and in MinGW compiler , there is a file "stdint.h" that also has the same line:
typedef unsigned short uint16_t;
When I compile, I get the following error:
error (dcc:1086):redeclaration of uint16_t
Can anyone please explain this to me .... I mean they are both unsigned short ..
uint16_t is already defined in stdint.h as an unsigned 16 bit integer type. You should just omit your typedef.

typedef error under gcc

in my code, I put following codes
typedef Status int;
I got following errors, it is expected '=', ',', ';', 'asm' or 'attribute' before 'int' under linux.
I can't find what's probelm. Thanks for your help.
a
Use:
typedef int Status;
instead of
typedef Status int;
The syntax of a typedef is the same as the syntax as any ordinary declaration:
int a, b; // declare int objects a and b
typedef int c, d; // declare int type-aliases c and d
The typedef should be followed by the type and then the name. Therefore, the typedef should look like this:
typedef int Status;
The syntax for typedef is
typedef <SOME_TYPE> new_name_for_some_type;
You are swapping the <SOME_TYPE> and new_name_for_some_type elements of the typedef syntax.

Resources