primary-expression error

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/ioctl.h>
5 #include <sys/time.h>
6
7 #define BS (32*1024)
8 char buf0[BS];
9 char buf1[BS];
10
11 #define SWAP64(p) ( (*(unsigned __int64*)(p)) = _byteswap_uint64(*(unsigned __int64*)(p)) )
12
13 int main(void)
14 {
15 int i,j;
16 FILE *ff = fopen("testFdd.dat","rb");
17 long pos0=0, pos1;
18
19 long max_k = 15;
20
21 while(1)
22 {
23 memset(buf1,0,BS);
24 pos1 = ftell(ff);
25 if( fread(buf1,BS,1,ff) != 1 ) break;
26 for(i=0 ; i<BS-4 ; i++ )
27 {
28 if( memcmp(buf1+i,"/fdd",4)==0 )
29 {
30 break;
31 }
32 }
33 if( i>=BS-4 ) continue; // didn't find
34
35 pos1 = pos1+i-0x40;
36 fseek(ff,pos1,SEEK_SET);
37 fread(buf1,1,BS,ff);
38 fseek(ff,pos1+0x41,SEEK_SET);
39
40 SWAP64(buf1);
41 SWAP64(buf1+0x18);
42 printf("%07x: %-7.7s %30s %lg %lg\n",pos1,buf1+8, buf1+0x20, *(double*)(buf1),* (double*)(buf1+0x18));
43 int n = pos1-pos0;
44 if( n>BS ) n=BS;
45 if( pos0!=0 && max_k-- > 0 )
46 {
47 printf("\n");
48 for( i=256+64 ; i<n ; i+=8 )
49 {
50 if( memcmp(buf0+i,buf1+i,8)!=0 )
51 {
52 SWAP64(buf1+i);
53 printf("\t+%04x: %+21.15le -> %+21.15le (%+16lg)\n",i, *(double*)(buf0+i),*(double*)(buf1+i),*(double*)(buf1+i)-*(double*)(buf0+i));
54 }
55 }
56 printf("\n");
57 }
58
59 pos0 = pos1;
60 memmove(buf0,buf1,n);
61 }
62 }
63
I'm trying to compile the above code, but i get error: expected primary-expression before ‘unsigned’
What is wrong with it? does anybody know?
Thanks
Line 25 is the likely culprit. U need to allocate memory with malloc/free or the c++ keywords new/delete (preferred) which stores the bytes returned from fread.

If that doesn't work consider using fstream instead of FILE
http://www.cplusplus.com/reference/iostream/istream/read/
Thank you for the suggestion. Tried the malloc, still problems. The same with fstream. I'm thoroughly stuck.
sry wish I could help more...maybe someone else can chime in ?
1) Please use code tags (the <> button) when posting code.
2) I received no errors when compiling the code after having to manually remove every line number (ugh).
3) Please post the full text of the error you're getting including the line number reported by the compiler.

@soranz - I see no issue with line 25. buf1 is defined at line 9 and is allocated as 32K bytes.
@AbstractionAnon Ah ok u're right. I saw the #define SWAP64 but i missed the other one for BS and declaration of buf1. Didn't even try to compile with those line #s in there lol
Last edited on
I posted the line numbers for easier communication.
What compiler are you using?
the line(s) that the compiler chokes on is 40, 41, and 52 the message is
40: error:expected primary-expression before 'unsigned'
I posted the line numbers for easier communication.

Appreciated but the code tags
[code]//code in here[code]
do this automatically and are formatted to not copy line numbers when we try out the code posted.

About the errors I don't know what the problem is exactly...It did compile for me too. I'll just say that I see a whole lot of casting and I'm wondering if it's all necessary ?
Last edited on
Thanks. Next time I'll follow the format rules.
For the error, I think it must be the compiler I'm using. It's good that it compiled for you and AbstractionAnon.
Yes but it'd be ideal if it compiled for u too :p
It worked under VS 2010 for me
Topic archived. No new replies allowed.