Log in

No account? Create an account
brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[May. 8th, 2000|10:46 pm]
Brad Fitzpatrick
[Tags|, ]

Who's the shit?
make_int_string (int ourInt, char *buffer, 
int buffersize, char **start, int *length)
int len = 1;
char *dig = &buffer[buffersize-1];
do {
*dig = (ourInt % 10) + '0';
ourInt /= 10;
if (ourInt) {
} while (ourInt);
*length = len;
*start = dig;
This is C code that gets to compiled to MIPS binaries, and then gets run on our project operating system.... the fragment above writes to a buffer the character representation of an integer, since we need it to output integers to the console/pipe/file ... heh ... this is fun. (Note to people that are good at C: don't mock my code ... I write Perl and SQL all day ... for me this is some high-quality stuff...... :-))

From: ex_lenz635
2000-05-08 10:55 pm (UTC)


That is artwork. It's beautiful :)
(Reply) (Thread)
[User Picture]From: bradfitz
2000-05-08 10:59 pm (UTC)

Re: Artwork

Damn skippy.
(Reply) (Parent) (Thread)
[User Picture]From: blythe
2000-05-08 11:07 pm (UTC)
Looks like gibberish to me.. hehehe :P j/kq
(Reply) (Thread)
[User Picture]From: eli
2000-05-08 11:07 pm (UTC)

Oh baby

Oh yes, that would be you, you're the shit.
(Reply) (Thread)
From: evan
2000-05-09 09:30 am (UTC)


Your code has a weird (ab)use of your buffer, doesn't it?
I've never seen something that uses the end of a buffer, and returns the address of the beginning of the data.

You could also kill the "if" (which feels redundant, because of the while condition) by putting the contents of the if at the beginning of the loop, and initializing len to 0 and dig to &buffer[buffersize]. :)

Doesn't writing code like this make you totally hate C? I'm sure you could do it in one line of Perl. :P
(Reply) (Thread)
[User Picture]From: bradfitz
2000-05-09 11:23 am (UTC)

Re: buffer

Yeah, sick isn't it? We also don't check if we *underrun* our buffer..... :-)
(Reply) (Parent) (Thread)