Thread: auto?

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    auto?

    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

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's the default keyword used for variables. The counterpart to static. If you have:
    Code:
    int num;
    it's the same as having:
    Code:
    auto int num;
    Your IDE should also be able to tell you that.

    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.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by itsme86
    It's the default keyword used for variables. The counterpart to static. If you have:
    Code:
    int num;
    it's the same as having:
    Code:
    auto int num;
    Your IDE should also be able to tell you that.

    EDIT: Regarding its usefulness see: http://www.eskimo.com/~scs/C-faq/q1.12.html
    Hmm. Can we expect to see it removed from the language in the future?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by ahluka
    Hmm. Can we expect to see it removed from the language in the future?
    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? gets


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Quote Originally Posted by quzah
    Want proof? gets
    Good point

    But well, I know people that want strcpy() to be removed because strncpy() is sooooo much safer

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.

  7. #7
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    You do get irony, do you?

  8. #8
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Actually the auto keyword is good for declaring vehicles:

    See question 1.8 of http://www.plethora.net/~seebs/faqs/...html#section-1


  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    53
    One word: LOL

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Are auto pointers any good?
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2007, 11:07 AM
  2. MDI client area auto sizing.
    By Rare177 in forum Windows Programming
    Replies: 1
    Last Post: 04-09-2005, 04:49 AM
  3. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  4. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 08:51 PM
  5. auto <cringe> generated <cringe> code <cringe>
    By RobS in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-22-2001, 04:46 AM