Ok I was reading a book on C++09 and saw this vareable auto that determins what kind of vareable it is. When I try to use it this comes up :
"auto will change c++x09 plesase remove it" I did the settings stuff and know I have 09 but how do I use auto? Google wasn't friendly in this siutuation. Also I hear auto is a keyword or somthing used in the olden days. What did it do
You are a bit confused with the standard numbering. What you seem to refer to as C++09 is actually not C++09. The newest standard which just came out this summer is called C++11 (as in, 2011). But, it has been in the making for quite some time (since the last standard revision, C++03), and during that time it was referred to as C++0x (as in, it was supposed to come out in year 200x, but the delays and deliberations lasted longer and it only came out in 2011). So, if you are looking for information on the
auto keyword, look for them on pages about either C++11 or C++0x, the wiki page is a good start.
Basically, the auto keyword allows you to create a variable whose type will be deduced by the compiler based on what it is initialized with:
auto some_variable = 5; //the compiler will deduce the type as 'int'. auto other_variable = 5.0; //the compiler will deduce the type as 'double'.
Sorry. I thought they where different things but the book was on chages from 03 to 09 and auto was in it. It also said it did something befor that and if I saw it in an old pice of code I'd have to remove it. So that's what the 11 means.
Edit: The book was c++ for dummies 5th? Edition. It was a little outdated.
What did it mean before it was used for a variable?
Edited by Zssffssz: n/a
>>What did it mean before it was used for a variable?
auto is a storage specifier in C (and kept in C++98). However, it is the default storage class for all variables in C/C++, which makes it a pretty meaningless specifier (i.e. it literally has no effect at all). A storage specifier is used to tell the compiler how long a variable should exist and where it should be stored or found.
Personally, I have never seen
auto used anywhere (after 13 years or so), I had to look it up to answer your question because I wasn't even aware it was a storage class in C++ (I thought that only
extern existed, which are the only ones that actually matter). Now, that I know about it, I am not surprised that I had never seen it before because it is clearly useless, i.e., it changes absolutely nothing.
In the C++98 standard, the storage specifiers
register are allowed because they exist in C and were kept for backward compatibility, however, they were essentially meaningless in C++98. The
register specifier has a theoretical but small effect, but it will be ignored by almost all modern compilers (it's basically a hint to help the compiler to optimize code, but modern compilers don't need such a hint anymore). Today, the new standard (C++11) still allows the
register specifier, but the allowance for the
auto keyword to appear as a storage specifier was removed (e.g. a syntax like
auto int b = 1; is illegal). It is OK to remove the support for
auto used in that way, because it had always been a C feature, and so, had never really been part of C++. As far as C is concerned, my understanding is that the
auto keyword is also completely useless, which is probably why I had never heard of it.
Edited by mike_2000_17: n/a
So is this the thing that C can do that C++ can't? Even if it is worthless it is cool that you just found an answer to a question that almost every C programer has asked.
PS By different things in my second post I ment like DIFFERENT things. The news article I read on C++11 made it sound less like a new standard and more like C++ is to C.
In a day or two I was goin to post a C++09 vs C++11 you just saved me a ton of emmbaresment.
Would the auto spesephyer thing work if I made the project under a C project? It would seem like a nifty way to word off people who don't read my code and use it and say it's there own.
Edited by Zssffssz: C
So is this the thing that C can do that C++ can't?
Um, no? C still allows the
auto keyword as a storage class specifier, but as Mike said, it's useless to anyone but a compiler writer. As far as C doing something that C++ can't, I'd say C++'s new interpretation of
auto is vastly more awesome. So even though C can use
auto as a totally redundant and pointless storage class specifier, C++ can use
auto for real improvements to the code. Thus C++ wins by a large margin on the
auto front. ;)
Even if it is worthless it is cool that you just found an answer to a question that almost every C programer has asked.
That question is only asked by insecure C programmers who are afraid of C++. Besides, there are many better answers to the question, such as implicit conversion of a pointer to void in both directions:
char *p = malloc(100); /* Valid C, invalid C++ */
char *p = (char*)malloc(100); /* Valid C and C++, but frowned upon in C */
By different things in my second post I ment like DIFFERENT things.
Aside from a few minor differences, C++03 is a superset of C95. However, C++11 and C99 have both evolved in different directions, so you can find more DIFFERENT things. Likewise, the C1x changes (not yet complete) will move the bar even further away.
Would the auto spesephyer thing work if I made the project under a C project?
It will work, certainly. It won't work according to the C++11 specification though.
It would seem like a nifty way to word off people who don't read my code and use it and say it's there own.
I am working on program that will connect to MySQL database, colect data from table and show them in grid. Where user can edit cell, and then on ...
I have an automated API with a secure frontend/backend structure where backend object attributes are hidden with frontend proxy classes.
basically, when accessing an object from the frontend, you get ...
Let say i have purchase 220 Bids for $30.80 , now i am going to place a bid for a product A, With each new bid the price goes up ...