Re: function return pointer of int?
On Nov 6, 3:44 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
Especially as it concerns an area in which C and C++ try to be
identical---all too often using different words to (hopefully)
say the same thing.
I'd missed that difference. Historically, of course, it made
sense, since you couldn't mix declarations and (other)
statements.
My main point still holds, of course: no C or C++ compiler will
accept pointer arithmetic on an incomplete type (and void is an
incomplete type). The code simply won't compile.
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Nov 6, 3:44 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
James Kanze <james.ka...@gm ail.comwrites:
On Nov 6, 7:39 am, Barry Schwarz <schwa...@dqel. comwrote:
On Wed, 5 Nov 2008 22:30:03 -0800 (PST), baichuan0...@16 3.com wrote:
[...]
void *fun(int i)
{
void *p = &i;
p += (1<<5) + 4;
{
void *p = &i;
p += (1<<5) + 4;
return p;
}
}
What do you think this accomplishes?
Your first executable statement contains a constraint violation.
I'm not sure what you mean by the "first executable
statement". The definition of p (with its initialization)
definitely generates executable code, and is executed. And
there's no problem with this statement; it is legal and well
defined, and must work in any implementation.
statement". The definition of p (with its initialization)
definitely generates executable code, and is executed. And
there's no problem with this statement; it is legal and well
defined, and must work in any implementation.
The cross-post is confusing matters (as always!).
identical---all too often using different words to (hopefully)
say the same thing.
In C there is a clear distinction between declarations and
statements, both in the formal syntax as well as in the less
formal text of the standard, so "the first statement" refers
unambiguously to the increment of p (and the extra
"executable " is redundant). In C++, as you know, there is a
"declaratio n statement" so the distinction is lost. Barry is
presumably assuming the code is C.
statements, both in the formal syntax as well as in the less
formal text of the standard, so "the first statement" refers
unambiguously to the increment of p (and the extra
"executable " is redundant). In C++, as you know, there is a
"declaratio n statement" so the distinction is lost. Barry is
presumably assuming the code is C.
sense, since you couldn't mix declarations and (other)
statements.
My main point still holds, of course: no C or C++ compiler will
accept pointer arithmetic on an incomplete type (and void is an
incomplete type). The code simply won't compile.
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Comment