Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

long long or char array?!

Name: Anonymous 2007-11-09 13:44

I need to store a value fit for an unsigned long long but i'm unsure wheather to use an actualy ull or a char array for it.

See this is all done by parsing encoded data, so when i encounted this value it will be in text form and i would have to use strtoull for conversion and storage.

This is all good and well, probably what i should do, if it wasn't for the second stage of my program.

You see later on i need to be able to process all the stored data i've parsed and recreate the encoded data it was parsed from. To do this with the ull value i would have to convert it back to a string.

So basically my question here is, should i use a ull value and make one end of the program simpler or should i put it in a string from the start and make the other end of the program simpler. Because if i don't use a char array to store it then i will have to figure out how to convert a ull value to a char array.

I have a function to convert integers to char arrays but it isn't mine, anyone who has read k&r will recognize it. To be honest it's kinda over my head, so writing one that supports ull would be a too difficult challenge for me.

Also, nothing i can see in the itoa function speaks against the fact that it can be converted to support ull simply by changing the argument definition, amirite or completely wrong?

void itoa(int n, char s[]) { /* K&R */
    int i, sign;

    if((sign = n) < 0) {
        n = -n;
    }
    i = 0;
    do {
        s[i++] = n%10+'0';
    } while((n /= 10) > 0);
    if(sign < 0) {
        s[i++] = '-';
    }
    s[i] = '\0';
    reverse(s);
}


I think writing this post helped me decide, i'll just go with storing it in a char array until i know more about converting ull to char **. I'll post this anyways just to spark discussion, also lispfags.

Name: lispfag 2007-11-09 13:53

no, nothing fucking changes.
also, this is a stupid problem. use bignums

Name: Anonymous 2007-11-09 15:00

Man, i'm stupid, i could just use snprintf to convert it back to a string. I was sitting here struggling with my own ulltoa function haha.

Name: Anonymous 2007-11-09 16:07

One word, Kernighan and Ritchie indentation. {
    Thread over
}

Name: Anonymous 2007-11-10 5:22

>>4
Truths were spoken.

I know indentation is a personal thing but i just prefer the one you see in the code example above. Though that has been cleaned up from the book, k&r uses the 'bracket-less' indentation a lot. Maybe to save space.

Lets change the direction of this discussion, I FUCKING HATE PEOPLE WHO USE THAT TYPE OF INDENTATION IN LARGE PROGRAMS!!!

I mean seriously, isn't it easier to read when it's properly structured with opening AND closing brackets?! To me it is!

I believe i've even read that in some 'secure programming' guide, that not using brackets can cause silly errors if you indent wrong. I avoid that from the get-go.

Now i don't have anything against people who put the opening bracket on it's own line because it matches the closing bracket more but my style is what you see above.

It feels almost like a lot of these practices are from the U.S. and an age when programmers were paid by the line.

For example a lot of code in the FreeBSD kernel indents like this.
int
main(args)
{
...
}


Or even worse when they use the other style of c function definition where you put the arguments on their own line.

These styles don't make it as hard to read as not using enclosing brackets but it still feels pointless to me.

Name: Anonymous 2007-11-10 6:12

>>5
read sicp

Name: Anonymous 2007-11-10 6:14

>>5

int
main(argc, argv)
int argc;
char *argv[];
{
    return !argv[argc];
}

Name: Anonymous 2007-11-10 6:15

i ment !!argv[argc];
!argv[argc] is not portable.

Name: Anonymous 2007-11-10 9:32

For example a lot of code in the FreeBSD kernel indents like this.
int
main(args)
{
...
}
Or even worse when they use the other style of c function definition where you put the arguments on their own line.

Read SICP then quit the internet forever.

Name: Anonymous 2007-11-10 10:13

long long is long

Name: Anonymous 2007-11-10 13:47

>>5
Your post is so confusing that I couldn't even grasp if you liked K&R indentation or not. Read SICP, then read an English grammar book.

Name: Anonymous 2007-11-10 15:17

long long cat;

Don't change these.
Name: Email:
Entire Thread Thread List