typedef struct pointer

is there a reason why all c compilers have no problem with declaring

header_file.h

typedef struct Program_Data_Struct *Program_Data_Struct;

while arduino spits out the error:

error: conflicting declaration 'typedef struct Program_Data_Struct * Program_Data_Struct'
typedef struct Program_Data_Struct *Program_Data_Struct;

How about posting enough code so we can try it ourselves?

there is no extra code needed,

if you create a header_file.h containing

typedef struct Program_Data_Struct *Program_Data_Struct;

and in your sketch you say:

#include "header_file.h"

you will generate the error

hewi:
you will generate the error

I just realized what you are trying to do...

typedef struct Program_Data_Struct *SomeName;

or

typedef struct Program_Data_Struct{} *SomeName;

yes, but I don't understand while all 'normal' c compilers accept the definition:

typedef struct Program_Data_Struct *Program_Data_Struct;

but yet again arduino wants none of it.

Latest gcc on Linux accepts it as does the latest avr-gcc command line but not though the IDE.

The error messages shown in the IDE

FRED-2:11: error: conflicting declaration 'typedef struct Program_Data_Struct* Program_Data_Struct'
 typedef struct Program_Data_Struct *Program_Data_Struct;
                                     ^
FRED-2:9: error: 'struct Program_Data_Struct' has a previous declaration as 'struct Program_Data_Struct'
 struct Program_Data_Struct{};
...

conflicting declaration 'typedef struct Program_Data_Struct* Program_Data_Struct'

makes sense since there does seem to be an ambiguity if one tries to use 'Program_Data_Struct',

hewi:
yes, but I don't understand while all 'normal' c compilers accept the definition:

typedef struct Program_Data_Struct *Program_Data_Struct;

but yet again arduino wants none of it.

Its a C++ thing (this is not C)

have you tried an anonymous struct:

typedef struct {} *Program_Data_Struct;

the whole point is data encapsulation, so it needs to be what it is, I know there is 100 different solutions. Also wrapping the definition inside extern "C" doesn't work :frowning:

I am again sad to see the arduino IDE differs from well established standards.

I think I am going to test code::blocks as sketch IDE.

hewi:
the whole point is data encapsulation, so it needs to be what it is.

It would also need to be what works, I suppose.

hewi:
I am again sad to see the arduino IDE differs from well established standards.

of C++?

I tried your expression on two other C++ compilers with the same error.

what is it you are actually trying to do, besides compiling that single line of code?

I am trying to implement a well known C programming idiom where you hide the data implementation from the interface.

This is a C++ environment.
Why not use the built-in idiom for encapsulation, instead of a knit-your-own?

AWOL:
This is a C++ environment.

that is mainly why I am changing IDE

Trying to compile that line of code with my "normal" C and C++ compilers failed as well. I use gcc version 4.6.3. You may want to re-think your assertion that all normal C compilers don't have a problem with that specific code.

One of the brilliant decisions that the Arduino implementers made was to not create their own language. They used the tried and trusted C++ language, and even used tried and trusted compilers. I have no "Arduino compiler". The Arduino IDE invokes the C++ tool chain I already have on my machine. Granted it has to have the ability to put out AVR machine code, but that's independent of the parsing.

Fighting with the compiler is nothing new to programmers. I think you have a few of options here.

  • Figure out how to fix your code so that the compiler that your IDE is invoking will accept it.
  • Figure out how to get the compiler that your IDE is invoking to accept that code. If stowite is correct, and the latest version of avr-g++ works with that code but not when invoked through the IDE, it could be an issue of compiler options.
  • Figure out why the compiler that your IDE is invoking doesn't accept that code, and fix the compiler. It is Open Source, after all.
  • Figure out how to get your IDE to invoke one of the "normal" compilers that you have that will accept that code.
  • Get a new IDE
  • Don't use an IDE

Ah... options. That's one thing I really love about the Arduino system. I can customize it however I want.

nail on the head, I was doing all the mentioned

thanks

This is strictly a matter of differences between C and C++.
The Arduino IDE has nothing to do with it.

C

struct Foo { ... };
struct Foo foo1;                    'struct' required
Foo foo2;                           error: type Foo not defined

typedef struct Foo { ... } *Foo;    OK: Foo and struct Foo are separate things

C++

struct Foo { ... };
struct Foo foo1;                    'struct' optional
Foo foo2;                           same as 'struct Foo foo2;'

typedef struct Foo { ... } *Foo;    error: conflicting definitions for type Foo

hewi:
is there a reason why all c compilers have no problem with declaring

header_file.h

typedef struct Program_Data_Struct *Program_Data_Struct;

while arduino spits out the error:

error: conflicting declaration 'typedef struct Program_Data_Struct * Program_Data_Struct'
typedef struct Program_Data_Struct *Program_Data_Struct;

It's because the arduino is a C++ compiler, not a C compiler. In C++, a struct declaration also declares the bare name as an identifier. In C, you always have to use "struct Foo", so there's no conflict.

we always used a locally-standardized syntax for struct typedefs, something like:

typedef struct foo_ { .... } foo_t;
:
foo_t foo;

(this pre-dates "anonymous structures" by a long time, and keeps the structure name (foo_), the type (foo_t) and the actual variable all nicely distinguished from one another.)

thank you all for the reply.

So I think I will have no choice but to find an IDE to generate the "HEX" file and then avrdude upload this to the boards I a m using ...

any advise on best choices?