The obvious thing I should've learned 5 years ago

Programming, for all ages and all languages.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

The obvious thing I should've learned 5 years ago

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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?
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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..
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: The obvious thing I should've learned 5 years ago

Post by Love4Boobies »

:shock:
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: The obvious thing I should've learned 5 years ago

Post by pcmattman »

Image
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: The obvious thing I should've learned 5 years ago

Post by Ferrarius »

Wow, That's so much more subtle than while loops in while loops.
Modular Interface Kernel With a lot of bugs ;)
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: The obvious thing I should've learned 5 years ago

Post 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).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Coty
Member
Member
Posts: 286
Joined: Thu Feb 12, 2009 5:12 pm

Re: The obvious thing I should've learned 5 years ago

Post 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.
My hero, is Mel.
Grunt
Member
Member
Posts: 37
Joined: Fri Nov 06, 2009 1:05 am

Re: The obvious thing I should've learned 5 years ago

Post by Grunt »

I never knew that C++ templates are Turing-complete until a coworker told me that.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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. :)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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.
Synon
Member
Member
Posts: 169
Joined: Sun Sep 06, 2009 3:54 am
Location: Brighton, United Kingdom

Re: The obvious thing I should've learned 5 years ago

Post 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

Code: Select all

const char* s = NULL;
, then s is a pointer to a

Code: Select all

const char
.
If the const is after the data type (and asterisk), as in

Code: Select all

char* const s = NULL;
, then s is a const pointer to a

Code: Select all

char
.

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

Code: Select all

char* hax = s
). 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:

Code: Select all

const char* const s = NULL;
I think I just made an invincible pointer.

I didn't know restrict though, thanks for that :)
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The obvious thing I should've learned 5 years ago

Post 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...
Post Reply