Typedef does not work to name a type

Hello,
This is related to the closed post in the forum for the installation of the same software called arachne, but with different error message:

In file included from ueberal/MiniSuperizer.cc:5:0:
./random/GnuRandom.h:54:5: error: �_G_uint32_t� does not name a type
     _G_uint32_t u;
     ^
./random/GnuRandom.h:59:5: error: �_G_uint32_t� does not name a type
     _G_uint32_t u[2];
     ^
./random/GnuRandom.h:73:13: error: �_G_uint32_t� does not name a type
     virtual _G_uint32_t asLong() = 0;

It seems the error is related to the #ifndef ... #endif block at the very beginning, but I am not sure how to debug this.

 33 #ifndef GNURANDOM
 34 #ifdef __GNUG__
 35 #pragma interface
 36 #else
 37 typedef int _G_int32_t
 38 #endif
 39 #define GNURANDOM
 40 
 41 #include <math.h>
 42 #ifdef __linux
 43 #include <_G_config.h>
 44 #else
 45 #include "random/GnuTypes.h"
 46 #include "random/GnuRandom.h"
 47 #endif
 48 #include "system/Assert.h"
 49 
 50 // RNG.h
 51 
 52 union PrivateRNGSingleType {            // used to access floats as unsigneds
 53     float s;
 54     _G_uint32_t u;
 55 };
 56 
 57 union PrivateRNGDoubleType {            // used to access doubles as unsigneds
 58     double d;
 59     _G_uint32_t u[2];
 60 };
 61 

The whole header file is "GnuRandom.h" but renamed as "GnuRandom.txt" here and attached for your reference. My PC kernel is:

Linux HP32 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

There would be a simple change but I just do not know. Thank you in advance!

Semicolon missing at the end of typedef

typedef int _G_int32_t;
1 Like

I added the semicolon, but got the same error!

Preprocess your code but don't compile it:

cc -E source.c -I... -o source.i

That will tell you what the compiler is actually doing to the source code, especially the #ifdef's.

The typedef cannot be digested by the preprocessor...it is meant for consumption only by the compiler so replace it with something like...

#define _G_int32_t int

Never do that.

Using #define creates code that is both syntactically and semantically different from using a typedef.

Consider the following code:

typedef char *charptr;
charptr a, b;

Now, replace that typedef

#define charptr char *
charptr a, b;

Not even close to the same code.

@achenle:
Embedded spaces in preprocessor #defines are always a cause of confusion and error...however the issue with the OP is one of supplying a compiler statement to a preprocessor...

That was a simple off-the-cuff example to demonstrate the semantic and syntax differences between "typedef" and "#define".

The fact that whitespace is treated completely differently in typedef and #define code is another reason to never replace typedef's with #define's.

If you read the link the OP provided, you'd see his problem is compiling. He's not feeding code to a preprocessor except as part of compiling. And I'd love to see a preprocessor so lame it couldn't handle typedef's, which are part of the language spec.

"Find out what's broken and fix it" is much better than "change this and hope it works".

1 Like

Thank you all! This is way more than expected.

Did some reading, it seems to me the problem is this part of the header:

#ifndef GNURANDOM
#ifdef __GNUG__
#pragma interface
#else
typedef int _G_int32_t ;   //This is the problem line
#endif
#define GNURANDOM

#include <math.h>
#ifdef __linux
#include <_G_config.h>
#else
#include "random/GnuTypes.h"
#include "random/GnuRandom.h"
#endif
#include "system/Assert.h"

which probably is NOT standard unsigned integer type.
The #ifdef/ifndef and #pragma make me confused with my OS Linux HP32 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux I conceptually understand #ifdef/#ifndef , and #pragma , but not sure under my present OS whether they are defined or not. How should I fix this? Thanks a lot!

Try adding the following line after the _G_int32_t typedef:

typedef unsigned int _G_uint32_t;
1 Like

Thank you everybody!
After reading this post, finally I got a workaround by replacing the problematic line with this one:

typedef int int32_t ; 

The problem may be related to the non-standard definitions of _G_int32_t and _G_uint32_t in the source code.
It worked after I made the replacements, anyway.