🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4043

Re: Binary includes

#4043
From: Markus Freericks
Date: Tue, 19 Sep 1995 09:07
46 lines
1919 bytes
In article <DF4Mt0.Cvw@cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
>  >   What about a syntax like :
>  >      static char table[] = {
>  >     #incbin "table.dat"
>  >      };
> 
> But what would the compiler do with all that garbage once it is included?
> The compiler expects tokens, so this would mean a new kind of token is
> invented that stands for binary data.

#incbin could tokenize the "included" file into byte-sized objects, i.e
expand to a comma-separated list of integer literals. If #incbin is
restricted to initializing character arrays, the proposal is fine (if not
overtly necessary, as a simple script can do the same).

IMHO the _real_ problem with this proposal is the *type*: how are

 static char char_table[] = {
 #incbin "foo"
 };

 static int int_table[] = {
 #incbin "foo"
 };

 static long long_table[] = {
 #incbin "foo"
 };

 static float float_table[] = {
 #incbin "foo"
 };

to do the "right" thing? OTOH, #incbin <type>,<filename> would be simple to
implement, if machine-dependent:

 static long long_table[] = {
 #incbin long,"foo"
 /* expands to 0x1234, 0x2364, ... , 0x2634 on a sizeof(long)=4 machine */
 };


here we have all those nice issues of byte-order and
number-of-bytes-in-a-long creeping in.

-- Markus
Technical Details
Message-ID: <ttmsplt2y0n.fsf@toulouse.cs.tu-berlin.de>
Path: arc1-ca.pugleaf.net!cs.tu-berlin.de!mfx
References: <43kt1g$ig@boson.epita.fr> <DF4Mt0.Cvw@cwi.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.tu-berlin.de!mfx
From: mfx@cs.tu-berlin.de (Markus Freericks)
Newsgroups: comp.std.c
Subject: Re: Binary includes
Date: 19 Sep 1995 11:07:20 +0200
Organization: Technical University of Berlin, Germany
Message-ID: <ttmsplt2y0n.fsf@toulouse.cs.tu-berlin.de>
References: <43kt1g$ig@boson.epita.fr> <DF4Mt0.Cvw@cwi.nl>
NNTP-Posting-Host: toulouse.cs.tu-berlin.de
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Original-Sender: mfx@toulouse (Markus Freericks)
In-reply-to: dik@cwi.nl's message of Tue, 19 Sep 1995 00:31:48 GMT
X-Newsreader: Gnus v5.0.4