473,748 Members | 7,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why not auto?

Hello,

Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?

Kind regards,
Vijay Kumar R. Zanvar

Nov 14 '05 #1
20 2868
"Vijay Kumar R. Zanvar" <vi*****@gmail. com> wrote:
Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?


No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?

Richard
Nov 14 '05 #2

Richard Bos wrote:
"Vijay Kumar R. Zanvar" <vi*****@gmail. com> wrote:
Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?
No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter

to be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?

Richard


But in one context, static is allowed to be used in function
parameters.

Vijay

Nov 14 '05 #3

"Vijay Kumar R. Zanvar" <vi*****@gmail. com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Hello,

Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?


Function parameters are already effectively 'auto'
(they go away when the function exits). What property
do you feel an 'auto' qualification would give a function
parameter?

-Mike
Nov 14 '05 #4
"Vijay Kumar R. Zanvar" <vi*****@gmail. com> wrote:
Richard Bos wrote:
"Vijay Kumar R. Zanvar" <vi*****@gmail. com> wrote:
Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?


No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either.


But in one context, static is allowed to be used in function
parameters.


Inside the size of an array declaration, yes. Not for the parameter
itself, and not as a storage class specifier.

The keyword "static" is the factotum of the C Standard, made to serve
whenever a small job is found that high-quality keywords such as
"register" and "for" consider beneath them. Most of these jobs have
nothing much to do with one another, and from static's presence in one
place you cannot derive any information about other uses of this jack-
of-all-trades. It has been said, quite possibly in comp.lang.c, that "it
[i.e., C99] wouldn't be a proper C Standard if it didn't find a new use
for 'static'".

Richard
Nov 14 '05 #5
On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:
No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?


Treat it as a suggestion (like register) that the value should be held
in 'static' memory rather than stack, for optimisation? For instance,
on a system where stack space is limited declaring all local variables
including parameters as static (knowing that the function wouldn't be
reentrant) might be useful.

Chris C
Nov 14 '05 #6
On Mon, 09 May 2005 20:04:38 +0100, Chris Croughton wrote:
On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:
No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?


Treat it as a suggestion (like register) that the value should be held
in 'static' memory rather than stack, for optimisation? For instance,
on a system where stack space is limited declaring all local variables
including parameters as static (knowing that the function wouldn't be
reentrant) might be useful.


This really boils down to a promise that the function won't be called
recursively, or concurrently from a signal handler. This would make more
sense as a attribute for the function as a whole rather than for
particular parameters.

Lawrence
Nov 14 '05 #7
On Tue, 10 May 2005 14:04:05 +0100, Lawrence Kirby
<lk****@netacti ve.co.uk> wrote:
On Mon, 09 May 2005 20:04:38 +0100, Chris Croughton wrote:
On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:
No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?


Treat it as a suggestion (like register) that the value should be held
in 'static' memory rather than stack, for optimisation? For instance,
on a system where stack space is limited declaring all local variables
including parameters as static (knowing that the function wouldn't be
reentrant) might be useful.


This really boils down to a promise that the function won't be called
recursively, or concurrently from a signal handler. This would make more
sense as a attribute for the function as a whole rather than for
particular parameters.


It might be needed only for certain parameters (long doubles and large
structs for instance) with others being in registers:

int doSomething(reg ister int action, static struct data);

I agree that a function attribute would also be useful. It can't be yet
another use of static, though, how about restrict? That has a similar
meaning (promise the compiler that you aren't going to do something
'clever' and non-optimisable):

restrict int wellBehavedFunc tion(int x, double y);

(Some compilers used for embedded systems have had their own extensions
to do similar things...)

Chris C
Nov 14 '05 #8
On Tue, 10 May 2005 14:59:22 +0100, Chris Croughton wrote:
On Tue, 10 May 2005 14:04:05 +0100, Lawrence Kirby
<lk****@netacti ve.co.uk> wrote:
On Mon, 09 May 2005 20:04:38 +0100, Chris Croughton wrote:
On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:

No storage class specifier except register can be used for function
parameters declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?

Treat it as a suggestion (like register) that the value should be held
in 'static' memory rather than stack, for optimisation? For instance,
on a system where stack space is limited declaring all local variables
including parameters as static (knowing that the function wouldn't be
reentrant) might be useful.
This really boils down to a promise that the function won't be called
recursively, or concurrently from a signal handler. This would make more
sense as a attribute for the function as a whole rather than for
particular parameters.


It might be needed only for certain parameters (long doubles and large
structs for instance) with others being in registers:

int doSomething(reg ister int action, static struct data);


The compiler is in a perfect position to know which parameters would
benefit from it. It doesn't need input from the programmer to determine
this, except to tell it that such optimisations are valid for the function
at all. It might be able to determine that for itself but in general it is
tricky. The compiler could also apply such optimisations to automatic
variables in the function body. Of course "stack" based allocation may be
more efficient on some implementations anyway, at the very least it is
likely to promote memory reuse and improved caching.
I agree that a function attribute would also be useful. It can't be yet
another use of static, though, how about restrict? That has a similar
meaning (promise the compiler that you aren't going to do something
'clever' and non-optimisable):

restrict int wellBehavedFunc tion(int x, double y);
Yes, that could work.
(Some compilers used for embedded systems have had their own extensions
to do similar things...)


Yes it can make a lot of sense for the smaller processors out there.

Lawrence

Nov 14 '05 #9
Chris Croughton wrote:
On Tue, 10 May 2005 14:04:05 +0100, Lawrence Kirby
<lk****@netacti ve.co.uk> wrote:
On Mon, 09 May 2005 20:04:38 +0100, Chris Croughton wrote:
On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:

No storage class specifier except register can be used for function
parameter s declarations. Not auto, but not static, extern or typedef
either. The reason, I suppose, is that declaring a function parameter to
be extern or auto makes even less sense than declaring it register.
Consider: whatever would it mean, a static function parameter?

Treat it as a suggestion (like register) that the value should be held
in 'static' memory rather than stack, for optimisation? For instance,
on a system where stack space is limited declaring all local variables
including parameters as static (knowing that the function wouldn't be
reentrant) might be useful.
This really boils down to a promise that the function won't be called
recursively , or concurrently from a signal handler. This would make more
sense as a attribute for the function as a whole rather than for
particular parameters.


It might be needed only for certain parameters (long doubles and large
structs for instance) with others being in registers:

int doSomething(reg ister int action, static struct data);

I agree that a function attribute would also be useful. It can't be yet
another use of static, though, how about restrict?


*g* We have still places where we can put static:

int wellBehavedFunc tion(int x, double y) static;
SCNR
Michael
That has a similar
meaning (promise the compiler that you aren't going to do something
'clever' and non-optimisable):

restrict int wellBehavedFunc tion(int x, double y);

(Some compilers used for embedded systems have had their own extensions
to do similar things...)


--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #10

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

Similar topics

2
2606
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this pattern for dynamical
1
13957
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the page the way I want. Does anybody know a solution for this? First of all, the code I am using: CSS ------- body {
5
6114
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge of the screen. I want it to only extend as far as it needs to to nicely contain the content within (a couple of links). Is width: auto the wrong property to do this? Is Mozilla rendering the style wrong?
6
5071
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
5
5043
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the CurrentUICulture to what's specified in the querystring. Since I want to allow UICulture auto detecting, I add UICulture = "auto" to page directive on each page.
5
3275
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what value it represents exactly (and does it apply for all elements/values you might apply 'auto' to?)
22
3081
by: nospam_news | last post by:
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.setErrNo(42);
2
3079
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.
21
6351
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
8989
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
8828
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
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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
3
2213
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.