Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Number of args in ``int fun();''

Name: Anonymous 2012-12-02 18:13

Hey /prog/, did you know  that you can do this in C:

int fun(); /* Whoops, we forgot ``void'' */

int main(int arg, char **argv)
{
  fun(fun, fun, "the Sussman", fun, fun, fun, (int)fun + (int)fun);
  return fun(3, 3, 3);
}

int fun()
{
  return 3;
}


It's been 6 years since I started writing C and I only now found out.  From a fucking C++ book.

Name: Anonymous 2012-12-02 18:21

If you want backward compatibility with K&R, your compiler has to support doing this (though any modern one will print a warning when it does). It will probably be deprecated eventually.

Name: Anonymous 2012-12-02 18:21

Yes, we know.

Name: Anonymous 2012-12-02 18:37

You weren't writing C if you didn't know this.

Name: Anonymous 2012-12-02 18:56

>>4
C's varargs are for fart commanders

Name: Anonymous 2012-12-02 22:50

Some people, when confronted with a problem, think ``I know, I'll use C.'' Now they have two problems.

Name: Anonymous 2012-12-02 23:22

>>6

Some people, when confronted with a post, think ``I know, I'll recite that JWZ quote!''  Now we have two shitposts.

Name: Anonymous 2012-12-03 5:14

Why can this be useful?..

Name: Anonymous 2012-12-03 5:17

>>8
think printf family of functions

Name: Anonymous 2012-12-03 5:28

>>9
Only va, nothing else?
By the way, how does printf work in C++ then?

Name: Anonymous 2012-12-03 5:56

>>10
dunno, external symbol as function wrapper maybe

it might have its uses like impersonating polimorphism with types like
struct{
    char type_name[32];
    void * vtable;
    ... state
}

Name: Anonymous 2012-12-03 6:29

>>8
A function pointer with that type is compatible with a lot of clearly defined functions.

Name: Anonymous 2012-12-03 7:08

>>12
Care to elaborate?

Name: Anonymous 2012-12-03 7:23

>>11
char type_name[32];

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Name: Anonymous 2012-12-03 8:19

>>9
The code in >>1 has nothing to do with varargs.

Name: Anonymous 2012-12-03 11:48

>>15
It could have va_start et cetera

Name: Anonymous 2012-12-03 12:47

>>13
typedef int (*int_fn)();

Now variables of type int_fn can hold a pointer to any function that returns an int.

Name: Anonymous 2012-12-03 13:21

JWZ
Shalom!

Name: Anonymous 2012-12-03 13:34

C is deprecated

Name: Anonymous 2012-12-03 13:54

>>19
That was ENTERPRISE QUALITY Genuine Advantage Certified!

Name: Anonymous 2012-12-03 15:17

>>16
Different mechanism, not compatible, etc.

Name: Anonymous 2012-12-04 4:34

>>17
My anus constricted.

Don't change these.
Name: Email:
Entire Thread Thread List