This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: making data files with gcc


Okay, what it seems like to me is that you expect your executable (or
object file) to contain nothing but the data that you encode in your C
file.

This is not at all true.  The compiler assumes that this will be used
as part of a program.  If you generate the assembly for your C file
(with -S option), you will see that in addition to your global data,
there are other bits and pieces needed for compilation.

If all you want is the data, you should write the data out to file,
and then read the data from file when you want to use it (using fread
and fwrite).

  Brian

On 12/26/05, Dale Walsh <websrvr@daleenterprise.com> wrote:
>
> On Dec 26, 2005, at 12:14 , Brian Budge wrote:
>
> > I think you left out the code that actually writes these structs to
> > file... that might help us identify the problem.
>
> I thought I listed the entire file but will list it again.
>
> I need more code????
> ___________________________
>
> test.c
> ___________________________
>
>    typedef struct
>    {
>         /* # of entries in data */
>         int entries;
>         /* entry size and count */
>         int size;
>         int cnt;
>         /* data; array of bytes, one row after another. */
>         char *data;
>    }
>    gFast;
>
> /* Location functions take these. */
>    typedef gFast * gFastPtr;
>
> char TestDATA[20];
>
> gFast gFastTestRep = {
>         2,
>         2,
>         10,
>         (char *)TestDATA,
> };
>
> /*
>     this is all the data
>     the file should be 32 bytes in length
>    20 bytes of data and 12 bytes for header
> */
>
> char TestDATA[] = {
>
>         /* Entry 000 */
>         1,2,3,4,5,6,7,8,9,10,
>
>         /* Entry 001 */
>         11,12,13,14,15,16,17,18,19,20,
> };
>
> gFastPtr gFastTest = &gFastTestRep;
> ___________________________
>
>
> I've tried compiling it with:
>
> gcc -c -static -o test.out test.c
>
> ___________________________
>
> this is the contents of the file after compiling with the above command.
>
> ___________________________
>
> 00000000  fe ed fa ce 00 00 00 12  00 00 00 00 00 00 00 01
> |................|
> 00000010  00 00 00 02 00 00 00 d8  00 00 20 00 00 00 00 01
> |.......... .....|
> 00000020  00 00 00 c0 00 00 00 00  00 00 00 00 00 00 00 00
> |................|
> 00000030  00 00 00 00 00 00 00 00  00 00 00 28 00 00 00 f4
> |...........(....|
> 00000040  00 00 00 28 00 00 00 07  00 00 00 07 00 00 00 02  |...
> (............|
> 00000050  00 00 00 00 5f 5f 74 65  78 74 00 00 00 00 00 00
> |....__text......|
> 00000060  00 00 00 00 5f 5f 54 45  58 54 00 00 00 00 00 00
> |....__TEXT......|
> 00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 f4
> |................|
> 00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
> |................|
> 00000090  00 00 00 00 00 00 00 00  5f 5f 64 61 74 61 00 00
> |........__data..|
> 000000a0  00 00 00 00 00 00 00 00  5f 5f 44 41 54 41 00 00
> |........__DATA..|
> 000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 28
> |...............(|
> 000000c0  00 00 00 f4 00 00 00 02  00 00 01 1c 00 00 00 02
> |................|
> 000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 02
> |................|
> 000000e0  00 00 00 18 00 00 01 2c  00 00 00 03 00 00 01 50
> |.......,.......P|
> 000000f0  00 00 00 24 00 00 00 02  00 00 00 02 00 00 00 0a  |...
> $............|
> 00000100  00 00 00 10 01 02 03 04  05 06 07 08 09 0a 0b 0c
> |................|
> 00000110  0d 0e 0f 10 11 12 13 14  00 00 00 00 00 00 00 24
> |...............$|
> 00000120  00 00 02 40 00 00 00 0c  00 00 02 40 00 00 00 0f
> |...@.......@....|
> 00000130  0f 02 00 00 00 00 00 10  00 00 00 19 0f 02 00 00
> |................|
> 00000140  00 00 00 24 00 00 00 01  0f 02 00 00 00 00 00 00  |...
> $............|
> 00000150  00 5f 67 46 61 73 74 54  65 73 74 52 65 70 00 5f
> |._gFastTestRep._|
> 00000160  54 65 73 74 44 41 54 41  00 5f 67 46 61 73 74 54  |
> TestDATA._gFastT|
> 00000170  65 73 74 00                                       |est.|
>
> ___________________________
>
>
> the valid data starts at '000000f4' and ends at '00000118'.
>
> If I need to do something more to get it in the format that I need
> I'b be more than happy to follow any instruction you provide.
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]