BASICFreak wrote:C is not my native language, learning so much within 1500 lines. I'm starting to miss the OO languages though - or at the very least standard libraries.
That's the best thing about osdev: You get to do everything from scratch. You'll end up deeply understanding a full complex system in full details.
BASICFreak wrote:And I'll continue to make my code C89 standard so I don't have to worry about anyone (mostly me) missing a -C99 gcc tag.
Just learn to use your compiler. Passing -std=c99 (or -std=gnu99 if you want extensions such as asm rather than __asm__) is easy and just takes a few moments to remember. Besides, you put that in build scripts anyways - other people building your code would be using these scripts too. I'd argue it is definitely worth the trade-off learning how to invoke your compiler compared with the advantages of not dealing with artificial ancient C restrictions. Note that it is called an option, not a tag.
BASICFreak wrote:C is not my native language, learning so much within 1500 lines. I'm starting to miss the OO languages though - or at the very least standard libraries.
That's the best thing about osdev: You get to do everything from scratch. You'll end up deeply understanding a full complex system in full details.
That's why I love it so much Learning far more than I thought I would.
BASICFreak wrote:And I'll continue to make my code C89 standard so I don't have to worry about anyone (mostly me) missing a -C99 gcc tag.
Just learn to use your compiler. Passing -std=c99 (or -std=gnu99 if you want extensions such as asm rather than __asm__) is easy and just takes a few moments to remember. Besides, you put that in build scripts anyways - other people building your code would be using these scripts too. I'd argue it is definitely worth the trade-off learning how to invoke your compiler compared with the advantages of not dealing with artificial ancient C restrictions. Note that it is called an option, not a tag.
And you know what sold me on C99, I had to get this all on one line to make it match everything else:
int stringToInt(unsigned int *out, char* in) {
unsigned int result = 0;
while (*in != 0) {
if ( (*in < '0') || (*in > '9') ) {
return BAD_CHAR;
}
if(result > UINT_MAX/10 ) {
return OVERFLOW;
}
result *= 10;
if(result > UINT_MAX - (*in - '0') ) {
return OVERFLOW;
}
ret += *in - '0';
*in++;
}
*out = result;
return OK;
}
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
BASICFreak wrote:And I'll continue to make my code C89 standard so I don't have to worry about anyone (mostly me) missing a -C99 gcc tag.
Just learn to use your compiler. Passing -std=c99 (or -std=gnu99 if you want extensions such as asm rather than __asm__) is easy and just takes a few moments to remember. Besides, you put that in build scripts anyways - other people building your code would be using these scripts too. I'd argue it is definitely worth the trade-off learning how to invoke your compiler compared with the advantages of not dealing with artificial ancient C restrictions. Note that it is called an option, not a tag.
Which makes me think you're not passing -Wall -Wextra (-Werror -pedantic) either even though that really teaches you to write proper C - more so than -std=c99
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
if (streql(explode_cmd[0], "echo")) for (int i = 1; i <= args; i++) printf ("%s ", explode_cmd[i]);
Please realize you are using a horrible indention style! Do not write such long convoluted lines for the sake of it, I don't know what gave you the idea that is a good style. Please adapt this indention style instead:
if (streql(explode_cmd[0], "echo"))
for (int i = 1; i <= args; i++)
printf ("%s ", explode_cmd[i]);
(Or any other sane indention style)
BASICFreak wrote:
I did have to go through my code and replace all (3) asm calls with __asm__ __volatile__
Did you not read my above post? The default option is -std=gnu89, which gives you C89 and GNU extensions such as asm volatile. You changed that to -std=c99 and got C99 but no GNU extensions. You'll want to use -std=gnu99 and get C99 and GNU extensions. Hell, use -std=gnu11!
BASICFreak wrote:
And still my favorite gcc warning:
CMD.c: In function 'doCommand':
CMD.c:50: warning: division by zero
CMD.c:50: warning: unused variable 'divz'
type div0 at prompt and what do you know 1/0 does not compute, still useful for faulting the system and testing my error source
Do you know what undefined behaviour is in C? If you are not entirely sure or have to guess, please do yourself an important favour and research the topic carefully. Zero division is undefined behaviour.