What the hell does auto do? Yep, I didn't search google, I want the info direct from a C guru who might be loitering
I was happily going to use auto as an identifier then my trusty IDE highlighted it. I've never seen it used anywhere before.
What the hell does auto do? Yep, I didn't search google, I want the info direct from a C guru who might be loitering
I was happily going to use auto as an identifier then my trusty IDE highlighted it. I've never seen it used anywhere before.
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
It's the default keyword used for variables. The counterpart to static. If you have:
it's the same as having:Code:int num;
Your IDE should also be able to tell you that.Code:auto int num;
EDIT: Regarding its usefulness see: http://www.eskimo.com/~scs/C-faq/q1.12.html
Last edited by itsme86; 10-06-2005 at 01:05 PM.
If you understand what you're doing, you're not learning anything.
Hmm. Can we expect to see it removed from the language in the future?Originally Posted by itsme86
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
No. They like to keep things for backwards compatability. Feel free to refer to this post in the future and say I'm wrong, but I won't hold my breath. Want proof? getsOriginally Posted by ahluka
Quzah.
Hope is the first step on the road to disappointment.
Good pointOriginally Posted by quzah
But well, I know people that want strcpy() to be removed because strncpy() is sooooo much safer
Yeah, but strcpy() is only unsafe when used on an untrusted source string. gets() is never safe.
Okay, I guess there's the extremely rare circumstance such as head -c 50 some_file | my_program_that_uses_gets_with_a_buffer_bigger_tha n_50 but come on...
strcpy() is perfectly safe as long as you know what you're doing with it.
If you understand what you're doing, you're not learning anything.
Actually the auto keyword is good for declaring vehicles:
See question 1.8 of http://www.plethora.net/~seebs/faqs/...html#section-1
One word: LOL
> because strncpy() is sooooo much safer
True, but the disaster normally strikes on the next line when you realise that strncpy() doesn't always copy the \0 at the end of the string, so something which expects to find a \0 is out of luck.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.