LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ReadFile byte count discrepancy

Hello, all,
 
I am trying to write data to a file that will be read by another, older program.  The data to be written has the following structure:
 
typedef struct {
     double dd;
     int ii;
     float array1[10];
     unsigned char array2[59];
} STRUCT;
 
When in my program I step through the ReadFile function in debug mode, ReadFile gives me a bytes-read count of 112.  But when I do the same in the older code, it gives me a bytes-read count of 111, which might explain why the older program cannot read my file correctly.  The older code uses a SetFilePtr statement (SetFilePtr (file, 0, 0)) prior to the ReadFile, but when I do the same in my code, there's no change in the byte count.  What might cause or account for such a discrepancy? 
 
Thanks,
 
Slowpoke
 
Slowpoke
CLAD (believe it or not!), using LabVIEW 8.5

They don't call me "Slowpoke" for nothin'!
0 Kudos
Message 1 of 4
(3,411 Views)

Forgot to mention the file in question above was in binary format.  Sorry!

Slowpoke

Slowpoke
CLAD (believe it or not!), using LabVIEW 8.5

They don't call me "Slowpoke" for nothin'!
0 Kudos
Message 2 of 4
(3,407 Views)
My guess would be that your old program makes different assumptions about structure packing than CVI does. CVI reports sizeof(STRUCT) in your example to be 112 when I try it. If you want to force no packing in your CVI program, simply wrap the structure in #pragma pack directives, like this.

#pragma pack(1) // 1-byte packing

typedef struct {
     double dd;
     int ii;
     float array1[10];
     unsigned char array2[59];
} STRUCT;

#pragma pack() // reset to default packing

With this change, I get sizeof(STRUCT) to be 111, as you expected.

Hope this helps,

-alex

0 Kudos
Message 3 of 4
(3,404 Views)

Help?  It saved my sanity!  It's just what I needed.  Thanks!

 

Slowpoke

Slowpoke
CLAD (believe it or not!), using LabVIEW 8.5

They don't call me "Slowpoke" for nothin'!
0 Kudos
Message 4 of 4
(3,379 Views)