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

Pages: 1-

error

Name: Anonymous 2007-11-17 16:07

`f' declared as function returning a function
int *f(int(*g)(int))(int){
 int ret(int n){
  return g(g(n));
 }
 return ret;
}

Name: Anonymous 2007-11-17 16:25

`f' declared as function returning a function
So?

Name: Anonymous 2007-11-17 16:53

>>2
The very notion of a function returning a function is absurd, in and of itself. I suspect >>1  is actually a troll.

Name: Anonymous 2007-11-17 16:59

>>3
Good job!

Name: Anonymous 2007-11-17 17:11

>>1
No, you can't have a pseudo-anonymous function in C/C++. But there's nothing wrong with returning a function from a function:

#include <iostream>

typedef int(*Fun)(int);

int anon_fun( int val ) {
        return val + 1;
}

Fun ret_fun() {
        return &anon_fun;
}

int main( int argc, char* argv[] ) {
        Fun f = ret_fun();
        std::cout << f( 9 ) << std::endl;
        return 0;
}


That said, this isn't nearly as powerful as what you can do in real functional languages. To squeeze some more juice out of C/C++, consider using boost.function with boost.bind.

inb4YHBT

Name: Anonymous 2007-11-17 17:24

if you're working on a plugin architecture system, you'll get used to function returning ptr of function

Name: Anonymous 2007-11-17 19:31

The very notion of a function returning a function is absurd, in and of itself. I suspect >>1  is actually a troll.


lol.... read SICP

Name: Anonymous 2007-11-17 19:44

>>7
YHBT

Name: Anonymous 2007-11-17 19:55

>>8
YHBT

Name: Anonymous 2007-11-17 20:05

>>8
>>9
/prog/

Name: Anonymous 2007-11-18 0:57

No, you can't have a pseudo-anonymous function in C/C++.
Why the fuck not?

Name: Anonymous 2007-11-18 3:27

>>11
Because, AFAIK, you can't. Give me some example code demonstrating that I'm wrong (without inlining any ASM), and I'll shut the fuck up.

Name: Anonymous 2007-11-18 7:39

Name: Anonymous 2007-11-18 8:25

Name: Anonymous 2007-11-18 12:30

>>14
Section 7.2.11.

Name: Anonymous 2007-11-19 10:42

This thread is hilarious comedy

Name: test 2009-10-03 12:06

>>6
~ $ cat crap.c
#include <stdio.h>

int main()
{
    int j;
    for(int i = 0; i < 100; ++i)
        j = i + 10;
    printf("%d\n", j);
}
~ $ gcc -std=c99 -O3 -Wall -Wextra -pedantic crap.c -S -masm=intel
~ $ cat crap.s
    .file    "crap.c"
    .intel_syntax noprefix
    .section    .rodata.str1.1,"aMS",@progbits,1
.LC0:
    .string    "%d\n"
    .text
    .p2align 4,,15
.globl main
    .type    main, @function
main:
    push    ebp
    mov    ebp, esp
    and    esp, -16
    sub    esp, 16
    mov    DWORD PTR [esp+4], 109
    mov    DWORD PTR [esp], OFFSET FLAT:.LC0
    call    printf
    xor    eax, eax
    leave
    ret
    .size    main, .-main
    .ident    "GCC: (GNU) 4.4.1"
    .section    .note.GNU-stack,"",@progbits


s/109/5950/ if you do j = 0 and j +=.
IHBT

Name: ​​​​​​​​​​ 2010-09-09 15:29

Name: Anonymous 2012-08-18 14:48

If we can't cure cancer, we should find a way to give cancer cancer, because then the cancer's cancer would kill the cancer. Can't argue with that logic.

Name: Anonymous 2012-08-18 16:11

GNU C supports lambdas. If you use an inferior version of C, then it's your own fault.

Name: Anonymous 2012-08-18 16:13

>>21

`
>GNU C
>just say GNO

Name: Anonymous 2012-08-18 18:22

>>21
GNU C considered harmful.

>>22
``>just say GNO"?
Who the fuck are you quoting?

Name: Anonymous 2012-08-18 18:59

>>21
GCC is shit.

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