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: Derek M Jones <derek AT knosof.co.uk>
  • To: c-semantics AT cs.illinois.edu
  • Subject: Re: [C-Semantics] function prototype scope
  • Date: Sun, 19 Jun 2011 02:49:40 +0100
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/c-semantics>
  • List-id: C Semantics in K Framework <c-semantics.cs.illinois.edu>
  • Organization: Knowledge Software, Ltd

Chucky,

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?

Yes, function definitions have prototypes.
S1011, http://c0x.coding-guidelines.com/6.5.2.2.html

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

S1711, http://c0x.coding-guidelines.com/6.8.html
are parameters initialized?
Yes, S1004, http://c0x.coding-guidelines.com/6.5.2.2.html

int (a, b, c) { ... } // this is wrong because a b c need types

Oh for the good ol' days when we had implicit int ;-)

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.

This is all conventional stuff. Wait until you encounter
old style function definitions that contain things that
were never supported when old style was all that was available,
eg, enum types (you might want to check out some of my old DRs
for interesting examples).

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

You need to read my C book a couple of times :-)

-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



--
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




Archive powered by MHonArc 2.6.16.

Top of Page