C vs C++ vs Lisp (156)

59 Name: #!/usr/bin/anonymous : 2008-07-27 09:45 ID:o893+jN4

>>49
Variadric functions need to be able to figure out how many arguments there are.

So a variadric strncmp would need 3 args for no length, or 4 for a max length number.

That's hardly an advantage over strcmp with 2 and strncmp with 3

Anyway, enough fail. Too many people want to add generic types to C, basically a typeof(void*) that returns what struct it is.

But then the usual way is to simply have the first field of the struct be an id int or string, and you cast it to a struct like that and get the id and then cast appropriately.

It's the thing that people forget. You just do it yourself in C.

Don't like C's strings? Then do some yourself... I've written my own "buffer" library, called dynbuf, which I use in my webserver.

Here's some of the header:

typedef struct
{
char *data;
size_t size;
size_t start_offset;
size_t end_offset;
} dynbuf;

dynbuf *dynbuf_create (size_t initial_size);

void dynbuf_append (dynbuf * db, const char *data, size_t size);
void dynbuf_append_from_file (dynbuf * db, FILE ** file, size_t read_size);

/* Successive calls will consume more and more of the buffer. The returned string points into the buffer, and is good until the buffer is fully consumed.*/
char *dynbuf_gets (dynbuf * db);

void dynbuf_grow (dynbuf * db, size_t size);
size_t dynbuf_length (dynbuf * db);

/* Return the data pointer+start_offset. The buffer will grow before it fills and it will always be Null terminated.*/
char *dynbuf_show (dynbuf * db);

/* Om nom nom precious data bytes I must eat them. */
void dynbuf_consume (dynbuf * db, size_t size);

void dynbuf_destroy (dynbuf * db);

This is what C is about, not complaining that someone didn't do 2 seconds of work for you already, and then force you to use it by making it the standard part of the language that all std functions use.

This thread has been closed. You cannot post in this thread any longer.