OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Feb 26, 2020 11:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: The obvious thing I should've learned 5 years ago
PostPosted: Fri Jan 29, 2010 7:54 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
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?

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Fri Jan 29, 2010 8:29 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
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?

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Fri Jan 29, 2010 9:04 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Fri Jan 29, 2010 10:44 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
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..

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 1:10 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
:shock:

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 2:30 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Image

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 4:45 am 
Offline
Member
Member

Joined: Sun Oct 28, 2007 4:10 pm
Posts: 69
Wow, That's so much more subtle than while loops in while loops.

_________________
Modular Interface Kernel With a lot of bugs ;)


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 5:23 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2008 2:34 pm
Posts: 548
Location: Belgium
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.


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 5:45 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1067
Location: Germany
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)


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 8:34 am 
Offline
Member
Member
User avatar

Joined: Thu Feb 12, 2009 5:12 pm
Posts: 286
Quote:
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.


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 10:17 am 
Offline
Member
Member

Joined: Fri Nov 06, 2009 1:05 am
Posts: 37
I never knew that C++ templates are Turing-complete until a coworker told me that.


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 12:45 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Redmond, WA, USA
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!


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 1:54 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
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:
while(..){
  if(....){
    //we need to go to the next iteration.
    skip=1;
  }
  if(!skip){
    //regular code...
  }
}


Yea, I feel dumb.

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 9:49 pm 
Offline
Member
Member

Joined: Sun Sep 06, 2009 3:54 am
Posts: 169
Location: Brighton, United Kingdom
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:
const char* s = NULL;
, then s is a pointer to a
Code:
const char
.
If the const is after the data type (and asterisk), as in
Code:
char* const s = NULL;
, then s is a const pointer to a
Code:
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:
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:
const char* const s = NULL;

I think I just made an invincible pointer.

I didn't know restrict though, thanks for that :)


Top
 Profile  
 
 Post subject: Re: The obvious thing I should've learned 5 years ago
PostPosted: Sat Jan 30, 2010 10:03 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
I think the reason most people don't know about restrict is that it wasn't (still isn't?) included in the C++ standard...

_________________
My new NEW blag


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: MSN [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group