I have the following lines in my source code which is giving the error
error C2275: 'HPDF_Array' : illegal use of this type as an expression"
:
This is the actual code in the header file:
typedef struct _HPDF_Array_Rec *HPDF_Array;
typedef struct _HPDF_Array_Rec {
HPDF_Obj_Header header;
HPDF_MMgr mmgr;
HPDF_Error error;
HPDF_List list;
} HPDF_Array_Rec;
HPDF_Array id;
How do I resolve this error?
This code works on my compiler (gcc 4.7.1), so maybe you need to show more code or information in general if you're still having trouble:
// content of this struct is irrelevant, so I just made a dummy struct
struct _HPDF_Array_Rec {
int dummy;
};
typedef struct _HPDF_Array_Rec *HPDF_Array;
HPDF_Array id;
What the code in your question does, is define the type HPDF_Array as a pointer to the type struct _HPDF_Array_Rec and instantiate one HPDF_Array (which is a pointer to a _HDPF_Array_Rec struct) called id
EDIT:
The code still works fine. I googled the errorcode and got this:
http://msdn.microsoft.com/en-us/library/76c9k4ah(v=vs.71).aspx
An expression uses the -> operator with a typedef identifier.
Check your code for that kind of error. Anywhere you're doing HPDF_Array->something instead of id->something ? :)
If you have error while compiling hpdf_pdfa.c file, then move
HPDF_Array id;
line to the beginning of the HPDF_PDFA_GenerateID(HPDF_Doc pdf) function.
It appears that 2.2.1 branch was built as a C++ code, and the committer didn't notice the error. In the trunk branch this error is fixed.
Related
I would like to "link" to a structure or member of a structure in Doxygen while displaying the text struct.member. My source code is in C.
For example, let's say I have the myStruct type/structure in C:
typedef struct
{
int member1;
int member2;
} myStruct;
And I would like to link/redirect within my Doxygen comments to documentation on myStruct while showing the text "myStruct.member1"
Example Doxygen Comments for a function:
You will receive the error code MEMBER_1_NOT_VALID if myStruct.member1 is larger than 5.
Where clicking on "myStruct.member1" redirects me to the documentation for myStruct.
I know that if I just have myStruct I could say "\ref myStruct", but doing "\ref myStruct.member1" does not work. Does anyone know how to make the documentation references work?
Any help is appreciated! Thank you.
I think the problem is that you defined the type and the structure together. Doxygen's parser seems to have problems with the mixed declaration of a struct and a typedef. Try to define the structure and the type definition seperately:
struct myStruct_s
{
int member1;
int member2;
};
typedef struct myStruct_s myStruct;
The you can reference the struct members using the tag name of the struct similar to as you already tried:
/**
* ...
* You will receive the error code MEMBER_1_NOT_VALID if \ref myStruct_s.member1
* is larger than 5.
* ...
*/
I am porting a windows assembly to linux. I have certain code to port. I am actually a newbie with C in linux. I know C fundamentals are the same yet!
typedef struct sReader
{
pReaderAddRef addRef;
pReaderDelRef delRef;
}pReader, *pSReader;
typedef long (*pReaderAddRef)(struct sReader *);
typedef long (*pReaderDelRef)(struct sReader **);
The above code give me the error 'pReaderAddRef' declared as function returning a function.
I understand the way callback functions work. But i dont really know how to resolve this error.
Kindly help.
While I don't understand your original error message - I get
f.c:3:5: error: unknown type name ‘pReaderAddRef’
f.c:4:5: error: unknown type name ‘pReaderDelRef’
with your original code -
it seems you mixed up the order: in order to use the function pointers, you must have them defined.
struct sReader; // incomplete type, but ready to be used
//alternatively:
typedef struct sReader pReader, *pSReader; // taken from your edit, but these prefixes are misleading
typedef long (*pReaderAddRef)(struct sReader *); // or mytypename
typedef long (*pReaderDelRef)(struct sReader **);
struct sReader
{
pReaderAddRef addRef; // Now you can use them
pReaderDelRef delRef;
}
In the following program I try to pass a structure to a function. But I get errors,and I do not understand why. What mistake have I made in this program ?
I am using gcc for compiling this c program.
#include <stdio.h>
struct tester {
int x;
int *ptr;
};
void function(tester t);
int main() {
tester t;
t.x = 10;
t.ptr = & t.x;
function(t);
}
void function(tester t) {
printf("%d\n%p\n",t.x,t.ptr);
}
Errors :
gcc tester.c -o tester
tester.c:8:15: error: unknown type name ‘tester’
tester.c: In function ‘main’:
tester.c:12:2: error: unknown type name ‘tester’
tester.c:13:3: error: request for member ‘x’ in something not a structure or union
tester.c:14:3: error: request for member ‘ptr’ in something not a structure or union
tester.c:14:13: error: request for member ‘x’ in something not a structure or union
tester.c: At top level:
tester.c:18:15: error: unknown type name ‘tester’
NOTE : If I replace printf with cout and stdio with iostream and name the extension to .cpp (!), I get no errors. Why is that ? No wonder I compile it using g++
If you don't typedef the struct you must specify struct in front of the struct name while declaring it like so:
struct tester t;
Either you do that or you do the following:
typedef struct {
int x;
int *ptr;
}tester;
Update
Below is a quote from Adam Rosenfield from the following post Difference between 'struct' and 'typedef struct' in C++?:
In C++, all struct/union/enum/class declarations act like they are implicitly typedef'ed, as long as the name is not hidden by another declaration with the same name.
your struct isn't named. either use struct tester t; or usa a typedef
The thing is you're trying to compile with gcc, which is a "c language" compiler and you're following C++ style of code.
It is possible to create a struct variable by just structname variablename;
but in c++, you explicitly have to tell the compiler it is a struct like
struct structname variablename;
Just do that and you'll be fine, otherwise you can use a typedef which is basically you tell the compiler form now on you are going to call struct tester to only tester, which will suit you more since you only have to only a minor change.
I have a header file buildTree.h and a C file buildTree.c there is a struct typedef'd in the header file and I would like one of the struct members to be of an enum type
the header file code is:
#define TREE_ITEM_LIMIT 100
typedef enum pType {
none = 0,
bool = 1,
number = 2,
baud = 3
}pType;
typedef struct tree {
// 27 byte size struct
char longName [13];
char shortName [5];
char shortParent [5];
ptype parameterType;
void (* handler)(int);
}tree;
extern tree item[TREE_ITEM_LIMIT];
extern tree defaultValues;
If i then attempt to assign a value to a the parameterType member in the C file a get a bucket-load of errors that basically say my struct is pretty screwy.
Whats really strange is that if I remove the assignment again, the errros dont go away the next time I compile! I have to remove the pType member from the struct, compile, then the errors are gone. If I add it back in again the errors stay gone until I try the assignment again...
Guessing Im not using the enum in the header correctly, but I cant see how...
EDIT: I did try commenting out the bool in the enum just in case that was playing up but no change
If this is because you mistyped "pType" as "ptype" in your struct, the gods will punish you.
And next time, read the very first line of error output and fix that.
naming a enumeration constant bool is a particularly bad idea. This is reserved for "stdbool.h", and you may get plenty of problems with at. If this is what you are facing we can't say, since you gave us neither your compiler version, nor the error output.
I’m trying to refactor and bring-over some old code, and I ran across something like this:
struct foo;
typedef struct foo * foo;
When attempting to compile it, I get the following sort of error:
Source/Types/Types.h:27:18: error: redefinition of 'foo' as different kind of symbol
typedef struct foo * foo;
^
Anybody know what’s causing this? I haven’t touched the code in a long time, but I certainly don’t remember any errors relating to that. It’s some of the most core code in the codebase, everything depends on it; I don’t see how I could possibly have missed such a glaring error, if it is indeed an error. Since the original foo is a “struct tag” (only a sane reference after the struct keyword), how can it conflict with my new foo typedef’d type?
Edit 1: Here’s the entire actual file, maybe I’m missing something, but it seems pretty straight-forward. It dumps a slew of the same errors described above, one for each type:
# if !defined(TYPE_DECLARATIONS)
# define TYPE_DECLARATIONS
# include "Core.h"
# warning "in Core.h"
static int class = 0; // to prove I’m not compiling as C++
struct e(fork);
typedef struct e(fork)* e(fork);
struct e(execution);
typedef struct e(execution)* e(execution);
struct e(thing);
typedef struct e(thing) e(thing);
struct e(typeRepresentation);
typedef struct e(typeRepresentation)* e(typeRepresentation);
struct e(typeRepresentation) {
void * family;
char name[64]; };
struct e(thing) {
void * const pointer;
e(typeRepresentation) const isa; };
# endif //!defined(TYPE_DECLARATIONS)
(Also, ignore the e() macro; it’s a noop in this case.)
Ah, I solved my own problem. I managed to screw up my e() macro such that it was literally preforming a noop, removing the code in question. :O
I’m an idiot. Sorry for wasting everyone’s time.
Are you now compiling this as C++, whereas it used to be compiled as C?
In C++, struct and enum tags live in the same namespace as other type names.
you associate the name foo with two different types. struct foo and a pointer to struct foo are different types.