Compilation Failed: warning: data definition has no type or storage class

C

Ced

Hi,

i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me what's wrong

regards


I get this error:

dmemory.h:66: parse error before `mem2ulong'
dmemory.h:66: warning: data definition has no type or storage class
dmemory.h:66: parse error before `ulong'
dmemory.h:71: parse error before `mem2uint'
dmemory.h:71: warning: data definition has no type or storage class
dmemory.h:71: parse error before `uint'

Here is the dmemory.h:

/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP
group */
/* See file COPYING 'GNU General Public Licence' for copyright details
*/
#ifndef _DMEMORY_H
#define _DMEMORY_H


#include <dnpap.h>


#ifndef HAS_UINT
typedef unsigned int uint;
#endif
#ifndef HAS_ULONG
typedef unsigned long ulong;
#endif
typedef WORD word;
typedef DWORD dword;
typedef LWORD lword;

#ifndef HAS_MEMMOVE
#define memmove(dst, src, n) bcopy((src), (dst), (n));
#endif


#define protconvtype(type) type mem2##type(BYTE *mem); \
void type##2mem(BYTE *mem, type val)

#ifdef ALIGNSECURE

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
type val; \
\
memcpy(&val, mem, sizeof(type)); \
return val; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
memcpy(mem, &val, sizeof(type)); \
}

#else

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
return *(type *)mem; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
*(type *)mem = val; \
}

#endif



#ifdef SPECIAL_MEMCMP
int memcmp(CONST VOID *b1, CONST VOID *b2, ULONG len);
#endif

protconvtype(long);
protconvtype(ulong);
protconvtype(word);
protconvtype(dword);
protconvtype(lword);
protconvtype(int);
protconvtype(uint);


#endif
 
J

Jarmo

Ced said:
Hi,

i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me what's wrong

regards


I get this error:

dmemory.h:66: parse error before `mem2ulong'
dmemory.h:66: warning: data definition has no type or storage class
dmemory.h:66: parse error before `ulong'
dmemory.h:71: parse error before `mem2uint'
dmemory.h:71: warning: data definition has no type or storage class
dmemory.h:71: parse error before `uint'

Here is the dmemory.h:

/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP
group */
/* See file COPYING 'GNU General Public Licence' for copyright details
*/
#ifndef _DMEMORY_H
#define _DMEMORY_H


#include <dnpap.h>


#ifndef HAS_UINT
typedef unsigned int uint;
#endif
#ifndef HAS_ULONG
typedef unsigned long ulong;
#endif
typedef WORD word;
typedef DWORD dword;
typedef LWORD lword;

#ifndef HAS_MEMMOVE
#define memmove(dst, src, n) bcopy((src), (dst), (n));
#endif


#define protconvtype(type) type mem2##type(BYTE *mem); \
void type##2mem(BYTE *mem, type val)

#ifdef ALIGNSECURE

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
type val; \
\
memcpy(&val, mem, sizeof(type)); \
return val; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
memcpy(mem, &val, sizeof(type)); \
}

#else

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
return *(type *)mem; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
*(type *)mem = val; \
}

#endif



#ifdef SPECIAL_MEMCMP
int memcmp(CONST VOID *b1, CONST VOID *b2, ULONG len);
#endif

protconvtype(long);
protconvtype(ulong);
protconvtype(word);
protconvtype(dword);
protconvtype(lword);
protconvtype(int);
protconvtype(uint);


#endif

I'd venture to say that both HAS_UINT and HAS_ULONG are defined macros and
yet you do not have a (native, or otherwise) typedef for uint or ulong.

If you undefine both macros so that the code uses the inline typedefs at
lines 13 and 16, what happens?
 
E

Ed Morton

Ced said:
Hi,

i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me what's wrong

regards


I get this error:

dmemory.h:66: parse error before `mem2ulong'
dmemory.h:66: warning: data definition has no type or storage class
dmemory.h:66: parse error before `ulong'
dmemory.h:71: parse error before `mem2uint'
dmemory.h:71: warning: data definition has no type or storage class
dmemory.h:71: parse error before `uint'

Here is the dmemory.h:

/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP
group */
/* See file COPYING 'GNU General Public Licence' for copyright details
*/
#ifndef _DMEMORY_H
#define _DMEMORY_H

If you're going to ask people for help debugging an error message that
refers to line numbers, it'd be courteous to provide the file with line
numbers especially when you're posting lines that are long enough to be
wrapped by many viewers. It would probably also encourage people to
consider your problem.

Ed.
 
E

Emmanuel Delahaye

Ced a pensé très fort :
Hi,

i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me what's wrong

Well, the code you provide is not for absolute beginners.
Here is a working solution with comments (-ed-), an implementation file
(dmemory.c) and a (minimum) test file (main.c).

Note that I have modified dmemory.h, and that I have probably broken
some GPL rule...

/* dmemory.h */

/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP
group */
/* See file COPYING 'GNU General Public Licence' for copyright details
*/
#ifndef _DMEMORY_H
#define _DMEMORY_H

/* -ed-
Unknown header. Removed.
#include <dnpap.h>
*/

/* -ed- missing definitions. 4 lines added (arbitrary definitions) */
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned long LWORD;

#ifndef HAS_UINT
typedef unsigned int uint;
#endif
#ifndef HAS_ULONG
typedef unsigned long ulong;
#endif
typedef WORD word;
typedef DWORD dword;
typedef LWORD lword;

/* -ed- memmove() is standard.
* (no idea what bcopy() is)
* 2 lines added
*/
#include <string.h>
#define HAS_MEMMOVE

#ifndef HAS_MEMMOVE
#define memmove(dst, src, n) bcopy((src), (dst), (n));
#endif

/* -ed- This is hard ro read
#define protconvtype(type) type mem2##type(BYTE *mem);
\
void type##2mem(BYTE *mem, type val)
* What about
*/
#define protconvtype(type) \
type mem2##type(BYTE *mem); \
void type##2mem(BYTE *mem, type val)

#ifdef ALIGNSECURE

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
type val; \
\
memcpy(&val, mem, sizeof(type)); \
return val; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
memcpy(mem, &val, sizeof(type)); \
}

#else

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
return *(type *)mem; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
*(type *)mem = val; \
}

#endif

#ifdef SPECIAL_MEMCMP
int memcmp(CONST VOID *b1, CONST VOID *b2, ULONG len);
#endif

protconvtype(long);
protconvtype(ulong);
protconvtype(word);
protconvtype(dword);
protconvtype(lword);
protconvtype(int);
protconvtype(uint);

#endif

/* dmemory.c */

#include "dmemory.h"

/* implementations */
defconvtype(long);
defconvtype(ulong);
defconvtype(word);
defconvtype(dword);
defconvtype(lword);
defconvtype(int);
defconvtype(uint);

/* main.c */

#include "dmemory.h"

#include <stdio.h>

int main (void)
{
BYTE mem[32] = {0};

word val = 0x1234;

printf ("data = %lX (before)\n", (unsigned long) val);

word2mem (mem, val);

val= mem2word (mem);

printf ("data = %lX (after)\n", (unsigned long) val);

return 0;
}

The result:

D:\CLC\C\CED>bc
data = 1234 (before)
data = 1234 (after)
 
P

Peter Shaggy Haywood

Groovy hepcat Ced was jivin' on 22 Jul 2004 07:41:42 -0700 in
comp.lang.c.
Compilation Failed: warning: data definition has no type or storage
class's a cool scene! Dig it!
I get this error:

dmemory.h:66: parse error before `mem2ulong'
dmemory.h:66: warning: data definition has no type or storage class
dmemory.h:66: parse error before `ulong'
dmemory.h:71: parse error before `mem2uint'
dmemory.h:71: warning: data definition has no type or storage class
dmemory.h:71: parse error before `uint'

I get all of these:

testing.c(9): Error! E1055: Unable to open 'dnpap.h'
testing.c(18): Error! E1022: Missing or misspelled data type near
'WORD'
testing.c(19): Error! E1022: Missing or misspelled data type near
'DWORD'
testing.c(20): Error! E1022: Missing or misspelled data type near
'LWORD'
testing.c(67): Error! E1009: Expecting ',' but found '*'
testing.c(67): Error! E1116: An id list not allowed except for
function definition
testing.c(67): Error! E1009: Expecting ',' or ';' but found 'mem'
testing.c(67): Error! E1009: Expecting ',' but found '*'
testing.c(67): Error! E1116: An id list not allowed except for
function definition
testing.c(68): Error! E1009: Expecting ',' but found '*'
testing.c(68): Error! E1116: An id list not allowed except for
function definition
testing.c(68): Error! E1009: Expecting ',' or ';' but found 'mem'
testing.c(68): Error! E1009: Expecting ',' but found '*'
testing.c(68): Error! E1116: An id list not allowed except for
function definition
testing.c(69): Error! E1009: Expecting ',' but found '*'
testing.c(69): Error! E1116: An id list not allowed except for
function definition
testing.c(69): Error! E1009: Expecting ',' or ';' but found 'mem'
testing.c(69): Error! E1009: Expecting ',' but found '*'
testing.c(69): Error! E1116: An id list not allowed except for
function definition
testing.c(70): Error! E1009: Expecting ',' but found '*'
testing.c(70): Error! E1147: Too many errors: compilation aborted
Error: Compiler returned a bad status compiling 'testing.c'
Here is the dmemory.h:

/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP
group */
/* See file COPYING 'GNU General Public Licence' for copyright details
*/
#ifndef _DMEMORY_H
#define _DMEMORY_H

Invades implementation name space. Avoid identifiers beginning with
underscores. (I take it you didn't write this code. In that case, I
can't blame you for this. But just bare it in mind for the future.)
#include <dnpap.h>

Non-standard header.
#ifndef HAS_UINT
typedef unsigned int uint;
#endif
#ifndef HAS_ULONG
typedef unsigned long ulong;
#endif
typedef WORD word;
typedef DWORD dword;
typedef LWORD lword;

Non-standard types.
#ifndef HAS_MEMMOVE
#define memmove(dst, src, n) bcopy((src), (dst), (n));
#endif

This is utterly pointless, since memmove() is a standard function
and bcopy() isn't.
#define protconvtype(type) type mem2##type(BYTE *mem); \
void type##2mem(BYTE *mem, type val)

Ye gads! Not only is the above macro incredibly ugly, but it is also
wrong. In the second half of this macro, the ## operator will join the
two tokens "type" (after it has been macro expanded) and "2", leaving
the token "mem" hanging. This is the cause of your problem.
#ifdef ALIGNSECURE

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
type val; \
\
memcpy(&val, mem, sizeof(type)); \
return val; \
} \
\
void type##2mem(BYTE *mem, type val) \

Same problem here.
{ \
memcpy(mem, &val, sizeof(type)); \
}

#else

#define defconvtype(type) \
type mem2##type(BYTE *mem) \
{ \
return *(type *)mem; \
} \
\
void type##2mem(BYTE *mem, type val) \
{ \
*(type *)mem = val; \
}

#endif



#ifdef SPECIAL_MEMCMP
int memcmp(CONST VOID *b1, CONST VOID *b2, ULONG len);
#endif

Pointless again, since memcmp() is standard.
protconvtype(long);

Now, let's examine what happens here, armed with an understanding of
the protconvtype macro. This line expands to this:

long mem2type(BYTE *mem); \
void long2mem(BYTE *mem, long val);

Tidied up it looks like this:

long mem2long(BYTE *mem);
void long2 mem(BYTE *mem, long val);

Now, you see that this sequence of characters, "2mem", is parsed as
the two tokens "2" and "mem", not a single token. Thus, upon expansion
of the above macro invocation, the sequence "type##2mem" is parsed as
"type ## 2 mem", and the result (after expansion of type) is "long2
mem".
protconvtype(ulong);
protconvtype(word);
protconvtype(dword);
protconvtype(lword);
protconvtype(int);
protconvtype(uint);

Of course, the same applies for all of these.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top