Learning how to program (23, permasaged)

17 Name: #!/usr/bin/anonymous : 2007-08-21 12:05 ID:1dSyuY9L

>>16

> char buffer[60] behaves very much like char *buffer

here are some examples

1:

int f(char **p) { ...
int main() {
char *p;
char buffer[10];
f(&p); /* correct */
f(&buffer); /* compiler complains, why? newbie is confused */

2:

char buffer[] = "BBC";
buffer[0] -= 1; /* "ABC" */
char *p = "BBC";
*p -= 1; /* segfault. newbie is confused */

*note: sure, you can fix this with this c99 feat

char *p = (char[]){ 'B', 'B', 'C', 0}

The newbie will be nonetheless confused

3:

char *p = "something";
/* ... */
p[-1] = 0; /* allowed */
char buffer[] = "something";
/* ... */
buffer[-1] /* undefined behavior */

Anyway, you make things sound easy, but you are correct, i do underestimate newbies.
That's what experience taught me... people don't want to learn, they want quick solutions.

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