Everything I wish I knew when learning C
11–20 of 401 posts
Re: Everything I wish I knew when learning C
#12 void main()
Still non-standard in C?Re: Everything I wish I knew when learning C
#13Nice, slowly "teaching" someone at work c for use on AIX. I will send him the link. I am not a very good teacher :)
Re: Everything I wish I knew when learning C
#14Thanks for submitting this. I'm teaching myself C so these high level overviews are super useful for improving my intuition. In the following example, shouldn't there be an asterisk * before the data argument in the getData function call? The way I understand it the function is expecting a pointer so you would need to pass it a pointer of the data object. > "If you want to “return” memory from a function, you don’t h…
No, it's correct. The asterisk is a little inconsistent, in that it means two opposite things. In the declaration it means "this is a pointer." However, in an expression , it means "this is the underlying type" and serves to dereference the pointer. int a = 5; int *x; // this is a pointer x = &a; int c = *x; // both c and *x are ints If it were *data, it would be equivalent to *(data + 0), which is equivalent to data…
int *x;
is declaring that the type of *x is int.Re: Everything I wish I knew when learning C
#15Earlier quoted context omitted.
No, it's correct. The asterisk is a little inconsistent, in that it means two opposite things. In the declaration it means "this is a pointer." However, in an expression , it means "this is the underlying type" and serves to dereference the pointer. int a = 5; int *x; // this is a pointer x = &a; int c = *x; // both c and *x are ints If it were *data, it would be equivalent to *(data + 0), which is equivalent to data…
The way I got this to stick in my head was to always think of * as dereferencing, and tell myself that int *x; is declaring that the type of *x is int.
int *x, y;
You're saying that both *x and y are integers.Re: Everything I wish I knew when learning C
#16This looks decent, but I'm (highly) opposed to recommending `strncpy()` as a fix for `strcpy()` lacking bounds-checking. That's not what it's for, it's weird and should be considered as obosolete as `gets()` in my opinion. If available, it's much better to do the `snprintf()` way as I mentioned in a comment last week, i.e. replace `strcpy(dest, src)` with `snprintf(dst, sizeof dst, "%s", src)` and always remember tha…
The strn* category was generally designed for fixed-size NUL-padded content (though not all of them because why be coherent?), the entire item is incorrect, and really makes the entire thing suspicious.
Re: Everything I wish I knew when learning C
#17Re: Everything I wish I knew when learning C
#18"Implicit declarations" is such a frustrating "feature" of C. Thankfully, in more recent clang builds this warning is enabled by default.
Re: Everything I wish I knew when learning C
#19Earlier quoted context omitted.
No, it's correct. The asterisk is a little inconsistent, in that it means two opposite things. In the declaration it means "this is a pointer." However, in an expression , it means "this is the underlying type" and serves to dereference the pointer. int a = 5; int *x; // this is a pointer x = &a; int c = *x; // both c and *x are ints If it were *data, it would be equivalent to *(data + 0), which is equivalent to data…
The way I got this to stick in my head was to always think of * as dereferencing, and tell myself that int *x; is declaring that the type of *x is int.
int *x = &a;
a bit more confusing/inconsistent.Re: Everything I wish I knew when learning C
#20Thanks for submitting this. I'm teaching myself C so these high level overviews are super useful for improving my intuition. In the following example, shouldn't there be an asterisk * before the data argument in the getData function call? The way I understand it the function is expecting a pointer so you would need to pass it a pointer of the data object. > "If you want to “return” memory from a function, you don’t h…