Re: Void function returns value



En news:fgaann$ut9$1@xxxxxxxx, Philip Potter va escriure:
Antoine Leca wrote:
void foo() {;}
int main() {
void *k;
k = foo;
The type of foo is [...] void(*)(void),

I believe there are no prototype in scope, so I think the type of
foo is rather void(*)().

Is that a distinct type?

My reading of 6.7.5.3p15 is that they are different, but compatible.

In both cases foo is declared as taking no arguments.

I read http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_317.htm as saying
that

void foo() {}

is also compatible with

void g(){ if(0) foo(1); }

While I know that

void foo(void);
void g(){ if(0) foo(1); }

should be diagnosed.


But I can easily be wrong on this one, so please check the holy words from
the knowledgeable people (there was a recent thread about this, subject was
"Prototype or not prototype?")


Antoine

.



Relevant Pages

  • Re: pass by Reference/value ???
    ... > void foo ... this would be called "passing by reference". ... foo receives a local copy of s and any changes that it makes to s only ... Since s is a pointer, a variable storing the address of s is a pointer to ...
    (comp.lang.cpp)
  • Re: Building extensibility into an API
    ... otherwise of "building extensibility into an API". ... Now maybe you think of some cool improvement to foo that you could make, ... foo_v2(int bar, char *baz, long double newparam); ... Each function you write takes an unused void * parameter. ...
    (comp.lang.c)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)
  • Re: Void function returns value
    ... "The value of a void expression (an expression that has ... void foo() ... I knew the compiler needs a function pointer, ...
    (comp.std.c)
  • Re: Simple Dispose Question
    ... void Foo(){ ... set to null (or go out of scope). ... we would wait for another long-running method to return and the ...
    (microsoft.public.dotnet.languages.csharp)