473,695 Members | 2,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usage of "auto". What for?

I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:

int main(char argc, char *argv[], char *env[]) {
try {
auto Exception mainException(1 );
mainException.s etErrNo(42);
} catch (Exception caughtException ) {
std::cout << "caught caughtException :" << caughtException .errNo <<
std::endl;
}
}

Of course you do not need the keyword auto to make the program
compile, link and run.
On the other hand, you (more clearly parsers) gain easy information
about where definitions are made !

As a plain developer reading his C++ file in an editor with the
indention used above it is mor ease to remember, that the auto
variables will be deconstructed, when going out of scope.

The other thing is, that you can use code parsers more easily to
process ascpects of variable usage for example.

May 9 '07 #1
22 3066
"no*********@wa nano.net" <To************ **@wanano.netwr ote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
>I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:
Then you're in for a treat:
http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf

Have fun rewriting your code once you switch to C++09 ;)

- Sylvester
May 9 '07 #2
At first sight I am really horrified.

Seems the principals of C++ are not at all interested in having a
stable language.
I.m.h.o. this is one reason ( in addition to the lack of an ABI
standards to allow for exchange of C++ binary libraries plus
headers ), why C++ looses followers against languages as C# for
example.
The less protection of development efforts by the standard, the more
readily you change.

A small community of indicate the downgrade of a language.
Of course there is middle-technology to connect the different
languages.

But there is an infrastructure around software development
( languages ) that is not solved by connective techniques, like
programmers, libraries, tools, discussions, ...

The idea of changing semantics and syntax of existing language
features is - to express it very politely - not necessariliy to the
advantage of the language.

May 9 '07 #3
"no*********@wa nano.net" <To************ **@wanano.netwr ote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
At first sight I am really horrified.

Seems the principals of C++ are not at all interested in having a
stable language.
I.m.h.o. this is one reason ( in addition to the lack of an ABI
standards to allow for exchange of C++ binary libraries plus
headers ), why C++ looses followers against languages as C# for
example.
I don't agree. C++ looses followers because C++ doesn't evolve as rapidly as
Java and C#. Besides, this very same auto feature will also makes it way
into C# 3.0, so according to your reasoning those who went to code C# will
also stop using C# for the very same reason they left C++.

And yes, you can misuse the new 'auto' feature just as you can misuse many
of the C++ features, but it's definitely a gain for those who deal with lots
of generic code and deeply nested template types. I, for one, am happy of
the new feature. I'm tired of writing std::vector<int >::iterator every time
while it's very obvious that if I call begin() on a vector it returns that
very same type (and this is just a mild nuisance).

- Sylvester
May 9 '07 #4
On 9 May, 11:15, "nospam_n...@wa nano.net"
<Torsten.Reich. ..@wanano.netwr ote:
At first sight I am really horrified.

Seems the principals of C++ are not at all interested in having a
stable language.
I.m.h.o. this is one reason ( in addition to the lack of an ABI
standards to allow for exchange of C++ binary libraries plus
headers ), why C++ looses followers against languages as C# for
example.
The less protection of development efforts by the standard, the more
readily you change.

A small community of indicate the downgrade of a language.
Of course there is middle-technology to connect the different
languages.

But there is an infrastructure around software development
( languages ) that is not solved by connective techniques, like
programmers, libraries, tools, discussions, ...

The idea of changing semantics and syntax of existing language
features is - to express it very politely - not necessariliy to the
advantage of the language.
You said yourself that your use of the auto keyword is in contrast to
the huge majority of C/C++ developers. For my part I have never once
seen it used in code and you are the first person I have ever
encountered, either online or in the real world, who uses it. If the
proposal were to change the meaning of a keyword like "class" or "if",
clearly that would be mad. There would be very little C++ code
unaffected. But auto in its current form has precisiely zero effect on
the compiler and is almost universally ignored by C++ programmers.
It's at the very top of the pointless keywords list, above even
register and inline. Given all that, while the general principle of
redefining the meaning of a keyword is quite alarming, in this
specific case I think the potential benefits of introducing a useful
capability that also exists (or will exist) in a competing language
outweigh the costs, which are extremely close to zero across the C++
world.

Gavin Deane

May 9 '07 #5
On May 9, 4:57 pm, "Sylvester Hesp" <s.h...@oisyn.n lwrote:
"nospam_n...@wa nano.net" <Torsten.Reich. ..@wanano.netwr ote in message

news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.
In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:

Then you're in for a treat:http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf
Oh I can't wait for this!

There are times that I've written a templated function as it was
easier than trying to work out the correct type of an iterator or some
other deeply nested type.
K

May 9 '07 #6
Sylvester Hesp wrote:
"no*********@wa nano.net" <To************ **@wanano.netwr ote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
>I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:

Then you're in for a treat:
http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf

Have fun rewriting your code once you switch to C++09 ;)
He won't have to. The present meaning of auto will be preserved; it
will just have another, much more useful, use. It will be like the many
different ways of using the "static" keyword.

Joe Gottman
May 9 '07 #7

"Joe Gottman" <jg******@carol ina.rr.comwrote in message
news:46******** *************** @roadrunner.com ...
Sylvester Hesp wrote:
>"no*********@w anano.net" <To************ **@wanano.netwr ote in message
news:11******* *************** @q75g2000hsh.go oglegroups.com. ..
>>I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:

Then you're in for a treat:
http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf

Have fun rewriting your code once you switch to C++09 ;)

He won't have to. The present meaning of auto will be preserved; it
will just have another, much more useful, use. It will be like the many
different ways of using the "static" keyword.
Interesting, do you have a source to back that up? Because if you read that
paper I just linked to, or the latest C++09 draft
(http://www.open-std.org/jtc1/sc22/wg...006/n2134.pdf), you
will see that the 'auto' storage specifier has been removed.

- Sylvester Hesp
May 9 '07 #8

"Sylvester Hesp" <s.****@oisyn.n lwrote in message
news:46******** *************@n ews.xs4all.nl.. .
>
>>Then you're in for a treat:
http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf

Have fun rewriting your code once you switch to C++09 ;)

He won't have to. The present meaning of auto will be preserved; it
will just have another, much more useful, use. It will be like the many
different ways of using the "static" keyword.

Interesting, do you have a source to back that up? Because if you read
that paper I just linked to, or the latest C++09 draft
(http://www.open-std.org/jtc1/sc22/wg...006/n2134.pdf), you
will see that the 'auto' storage specifier has been removed.

- Sylvester Hesp
Besides, it would make sense to remove it. Rather than with 'static', the
new usage for 'auto' is used in exactly the same context as the old usage,
which can conflict with eachother:

typedef int foo;
void bar(int i)
{
auto foo(i); // #1
}

What is the meaning of the statement at #1? Is it a definition of a local
variable i of type int, that has automatic storage duration? Or is it a
definition of a local variable foo, initialized with the int i, where it's
type is deduced from it's initialization? Currently, it is the former. But
after N1984 is implemented, it is the latter. You can't keep the former use
of auto alive because that will result in ambiguities in the language.

- Sylvester Hesp
May 9 '07 #9
On 2007-05-09 03:15:35 -0700, "no*********@wa nano.net"
<To************ **@wanano.netsa id:
At first sight I am really horrified.
[at the C++09 semantics of the auto keyword]
The idea of changing semantics and syntax of existing language
features is - to express it very politely - not necessariliy to the
advantage of the language.
I would agree with you if it weren't for the fact that the auto
keyword, as it exists, is completely useless. It effectively has *no
semantics to change*. Anyone currently using it in any real code is,
IMHO, simply being different for difference's sake.

--
Clark S. Cox III
cl*******@gmail .com

May 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
20497
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number can go without the system crashing. An ancillary question is how one resets an auto number so that the sequence starts again at 1. In the case of this file, the auto number field serves no useful purpose except as an
1
2479
by: PL | last post by:
The Culture="auto" UICulture="auto" is a great idea, but how do you handle the situaion where SQL Server always requires a dot "." in numeric values. If I use Culture="auto"so that dates and numbers are formatted depending on the browser settings I will encounter situations where values come in as for example "52,50" using a comma instead of a dot. I could go over the whole site and make sure I replace any commas with dots before...
1
4055
by: Jefferds.A | last post by:
Hi, I'm putting together a little database of individuals categorized by family. I have two lists, one that contains family names and one that contains individuals' names. When you click on a link in the first list, it generates from a mysql database all the people associated with that family. When you click on an individual's name, it displays biographical information. The catch is, for space, I've put these lists in little boxes...
9
18847
by: Beowulf | last post by:
I was having this problem: http://groups.google.com/group/microsoft.public.sqlserver.server/msg/e36e423972323378?dmode=source with it taking an inordinate amount of time to enumerate the databases on my local SQL Server instance, so I went through all the local databases and unchecked "Auto Close" on the "Options" tab of the Database properties in Enterprise Manager. This cleared up the problem nicely. In EM or through SQL-DMO, the...
2
3073
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value ("auto") in JavaScript - however instead of getting "auto" value, I get calculated height. In IE and Opera it simply returns "auto". Any ideas how to check in Firefox if element height was set to "auto" ? I'll be grateful for any help.
0
8619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5831
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4336
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2258
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.