Page 1 of 3
The obvious thing I should've learned 5 years ago
Posted: Fri Jan 29, 2010 7:54 pm
by earlz
So I'm a self-taught C programmer. Well, after about a year or two of C programming/OS hacking, I taught myself just about everything. Structs, enums, function pointers, etc etc.. (I learned unions about 3 or 4 years after starting C btw cause I see very little use for them)
Well, I was just skimming through my book for C++(I already know about everything in the book except for where it barely touches on templates) for a class and in chapter 3 (read: chapter that is taught 4 weeks into the class) and I discovered this keyword. `continue` I looked and realized I'd seen it some places but actually had no idea what it was.
How could I have actually not known about this amazing keyword!? Been programming C for over 5 years now and I'm just NOW figuring out that there is a `continue` keyword!? When I learned Ruby, I thought C was extremely lacking because of it's lack of a `next` keyword... Well, la de da it was right there...
Hopefully, the continue keyword isn't news to you, but share your similar experiences. What is missing in your knowledge that is so basic that you should've learned it after a week of beginning programming?
Re: The obvious thing I should've learned 5 years ago
Posted: Fri Jan 29, 2010 8:29 pm
by pcmattman
The continue keyword should be one of the fundamentals you learn when you learn loops... or so I thought?
I guess you wouldn't know what the restrict keyword is for, then?
Re: The obvious thing I should've learned 5 years ago
Posted: Fri Jan 29, 2010 9:04 pm
by Firestryke31
With C/C++, there's still a lot I have yet to learn (like where to put const for different situations, or memorizing template syntax), but continue is something I've known since pretty close to the beginning. I do admit, though, that I've forgotten about it once or twice, since I don't often need it.
Re: The obvious thing I should've learned 5 years ago
Posted: Fri Jan 29, 2010 10:44 pm
by earlz
pcmattman wrote:The continue keyword should be one of the fundamentals you learn when you learn loops... or so I thought?
I guess you wouldn't know what the restrict keyword is for, then?
Just looked up what restrict is.. Pretty hardcore.. lol
And yea, I also don't have the whole const/volatile order memorized for pointers..
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 1:10 am
by Love4Boobies
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 2:30 am
by pcmattman
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 4:45 am
by Ferrarius
Wow, That's so much more subtle than while loops in while loops.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 5:23 am
by Creature
pcmattman wrote:The continue keyword should be one of the fundamentals you learn when you learn loops... or so I thought?
I guess you wouldn't know what the restrict keyword is for, then?
I've heard about pretty much all the standard C/C++ keywords before but pretty much never used all of them. For example, I've never had any use for the
mutable keyword, which states that a member of a class can still be modified, even if the object of the class is defined as
const (or at least that's what I thought it was).
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 5:45 am
by Kevin
earlz wrote:How could I have actually not known about this amazing keyword!? Been programming C for over 5 years now and I'm just NOW figuring out that there is a `continue` keyword!?
So your code was full of gotos to replace continue?
Not nearly as basic, but I didn't know about C99 compound literals for a long time.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 8:34 am
by Coty
Hopefully, the continue keyword isn't news to you,
It IS... news to me
Never made it past chapter 3 of C++ for
dummies before I went back to ASM.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 10:17 am
by Grunt
I never knew that C++ templates are Turing-complete until a coworker told me that.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 12:45 pm
by Colonel Kernel
Grunt wrote:I never knew that C++ templates are Turing-complete until a coworker told me that.
Only in theory... Most compilers have pretty hard limits on the depth of template recursion they support.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 1:54 pm
by earlz
Kevin wrote:earlz wrote:How could I have actually not known about this amazing keyword!? Been programming C for over 5 years now and I'm just NOW figuring out that there is a `continue` keyword!?
So your code was full of gotos to replace continue?
Not nearly as basic, but I didn't know about C99 compound literals for a long time.
No, it was more like
Code: Select all
while(..){
if(....){
//we need to go to the next iteration.
skip=1;
}
if(!skip){
//regular code...
}
}
Yea, I feel dumb.
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 9:49 pm
by Synon
earlz wrote:pcmattman wrote:And yea, I also don't have the whole const/volatile order memorized for pointers..
I've been programming C for less than a year, and I know it :l
If the const is before the data type, as in
, then s is a pointer to a
.
If the const is after the data type (and asterisk), as in
, then s is a const pointer to a
.
So in the first case, you can re-point s, but you can't modify what s points to (unless you use another pointer, like
). In the second case, you can't repoint s, but you can change the value it points to.
What I want to know is what happens if I do this:
I think I just made an invincible pointer.
I didn't know restrict though, thanks for that
Re: The obvious thing I should've learned 5 years ago
Posted: Sat Jan 30, 2010 10:03 pm
by earlz
I think the reason most people don't know about restrict is that it wasn't (still isn't?) included in the C++ standard...