Skip to Content.
Sympa Menu

c-semantics - Re: [C-Semantics] function prototype scope

c-semantics AT lists.cs.illinois.edu

Subject: C Semantics in K Framework

List archive

Re: [C-Semantics] function prototype scope


Chronological Thread 
  • From: Chucky Ellison <celliso2 AT illinois.edu>
  • To: Derek M Jones <derek AT knosof.co.uk>
  • Cc: c-semantics AT cs.illinois.edu
  • Subject: Re: [C-Semantics] function prototype scope
  • Date: Sat, 18 Jun 2011 17:56:54 -0500
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/c-semantics>
  • List-id: C Semantics in K Framework <c-semantics.cs.illinois.edu>

I saw 403, but aren't all definitions also declarations? Isn't "int
f(int x) { ... }" both a definition and a declaration? In "int f(int
x) { ... }", isn't "int f(int x)" a declaration and a prototype?

Regardless of the above, I see 408 and 409 explain what it is, and why
it is not function prototype scope. I'm assuming that the above is a
prototype, and the parenthetical remark in 409 is what makes it not
"function prototype scope" even though it is a function prototype.

I'm still not sure about evaluation order though. In this code:
int f(int a[A], int b[B]) { ... }

Must 'A' evaluate before 'B'? My guess is that it is supposed to
execute as if there were declarations in order like:
{
int a[A];
int b[B];
...
}?

This makes me think of the "old style" declarations, which I'm also
still confused about. My current working summary is that everything
must have an explicit base type:
static int a;
vs
static a;

and
int f() { ... }
vs
f() { ... };

int (a, b, c) { ... } // this is wrong because a b c need types
int (a, b, c) int a; int b; int c; { ... } // this is okay because
they have types now

Also, something like
int f();
int g(void) {
return f(5);
}
int f(int x) {
return x;
}
I think this is a correct program, and calling g() will return 5.

I've seen all this code in practice, and I see a lot of conflicting
information about this on the web. For example, this article from
intel says that C99 disallows the use of old style declarations
(http://software.intel.com/en-us/articles/old-style-c-function-argument-declarations-are-supported/).
The C1X standard mentions "old style" so I figure they must be
allowed (n1570 6.7.6.3:15 footnote 146), even if I can't find their
semantics described anywhere.

Any insight into all these declaration issues are much appreciated :)

-Chucky

On Sat, Jun 18, 2011 at 12:28 PM, Derek M Jones
<derek AT knosof.co.uk>
wrote:
> Chucky,
>
>> int sub (int i, int array[i++]) {
> ...
>> I'm pretty sure this is "function prototype scope" and that "i++" is
>
> No it isn't.
> Sentence 403: http://c0x.coding-guidelines.com/6.2.1.html
> Also see sentence 408.
>
>> not an integer constant expression, so it should be treated like a
>> "*".  My understanding of the "*" in array declarators is fuzzy, but I
>> don't think they are allowed to be used in a definition, only in a
>> function declaration.  Indeed, all of the compilers complain with an
>> error if I try:
>>      int sub (int i, int array[*]) { ... }
>> Instead, doing this:
>>      int sub (int i, int array[*]);
>>      int sub (int i, int array[10]) { ... }
>> compiles and runs.
>>
>> If i++ is supposed to be evaluated (although I don't know how, based
>> on the above 6.7.6.2:5), then when does it get evaluated?  During
>> every call?  At definition time?  Are the side effects guaranteed to
>> occur?  Where should I be looking in the standard instead of the
>> quotes above?
>>
>> Does anyone know what is going on here?
>>
>> -Chucky
>> _______________________________________________
>> c-semantics mailing list
>> c-semantics AT cs.illinois.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/c-semantics
>>
>
> --
> Derek M. Jones                         tel: +44 (0) 1252 520 667
> Knowledge Software Ltd                
> mailto:derek AT knosof.co.uk
> Source code analysis                   http://www.knosof.co.uk
> _______________________________________________
> c-semantics mailing list
> c-semantics AT cs.illinois.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/c-semantics
>





Archive powered by MHonArc 2.6.16.

Top of Page