[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] uint8_t, unsigned char, and char for BufferedFile (and o
From: |
Peter \"Firefly\" Lund |
Subject: |
[Tinycc-devel] uint8_t, unsigned char, and char for BufferedFile (and others) |
Date: |
Fri, 2 May 2003 20:35:10 +0200 (MEST) |
The buffered file implementation in TinyCC revolves around the
BufferedFile type.
#define IO_BUF_SIZE 8192
typedef struct BufferedFile {
uint8_t *buf_ptr;
uint8_t *buf_end;
int fd;
int line_num; /* current line number - here to simply code */
int ifndef_macro; /* #ifndef macro / #endif search */
int ifndef_macro_saved; /* saved ifndef_macro */
int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
char inc_type; /* type of include */
char inc_filename[512]; /* filename specified by the user */
char filename[1024]; /* current filename - here to simplify code */
unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char
*/
} BufferedFile;
#define CH_EOB '\\' /* end of buffer or '\0' char in file */
#define CH_EOF (-1) /* end of file */
...
static int ch, tok;
It contains an 8K buffer that is used most of the time. In some cases
buf_ptr (and buf_end) are set to other character arrays outside of
BufferedFile. This happens in tcc_compile_string() and
tcc_define_symbol().
The value of CH_EOF must be distinct from all possible values for a
character element in the buffer. I guess that is why the value -1 and the
type unsigned char (and uint8_t) are chosen.
Other combinations are possible: 128/-128 and (signed) char, for example.
Sometimes a buf_ptr or buffer field is passed as a parameter to functions
that really want to take char *'s:
pstrcpy(), pstrcat(), strlen()
I would prefer to keep pstrcpy()/pstrcat()/strlen() as taking char *'s,
change buffer, buf_ptr, and buf_end to use char's too and change CH_EOF to
-128.
Even on a 9-bit machine where a signed char can hold -256 .. 255 this
ought to work as long as we only try to read ASCII source files.
Comments?
-Peter
- [Tinycc-devel] uint8_t, unsigned char, and char for BufferedFile (and others),
Peter \"Firefly\" Lund <=