Skip to main content
deleted 98 characters in body
Source Link
ugoren
  • 17.5k
  • 5
  • 52
  • 74

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude#include <stdio.h>
#inc lude#include <errno.h>

void f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
}

int *main() {
        f(main);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with main as a parameter leads to endless recursion.

EDIT: The previous version crashed, but not because of a stack overflow. Fixed.

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

void f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
}

int *main() {
        f(main);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with main as a parameter leads to endless recursion.

EDIT: The previous version crashed, but not because of a stack overflow. Fixed.

C

A simple recursion. But where's the recursive call?!

#include <stdio.h>
#include <errno.h>

void f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
}

int *main() {
        f(main);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with main as a parameter leads to endless recursion.

EDIT: The previous version crashed, but not because of a stack overflow. Fixed.

deleted 22 characters in body
Source Link
ugoren
  • 17.5k
  • 5
  • 52
  • 74

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

intvoid *ff(int errno) {
        if (errno==EINVAL) puts("EINVAL");
        return NULL;
}

int main*main() {
        f(fmain);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with itselfmain as a parameter leads to endless recursion.

EDIT: The previous version crashed, but not because of a stack overflow. Fixed.

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

int *f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
        return NULL;
}

int main() {
        f(f);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with itself as a parameter leads to endless recursion.

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

void f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
}

int *main() {
        f(main);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location())
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location.
When this is expanded in the body, this function is called.
Calling f with main as a parameter leads to endless recursion.

EDIT: The previous version crashed, but not because of a stack overflow. Fixed.

added 9 characters in body
Source Link
ugoren
  • 17.5k
  • 5
  • 52
  • 74

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

int *f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
        return NULL;
}

int main() {
        f(f);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location()) 
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location. 
When this is expanded in the body, this function is called. 
Calling f with itself as a parameter leads to endless recursion.

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

int *f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
        return NULL;
}

int main() {
        f(f);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location()) When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location. When this is expanded in the body, this function is called. Calling f with itself as a parameter leads to endless recursion.

C

A simple recursion. But where's the recursive call?!

NOTE: The include lines have a space in them, for "security" reasons. Edits are welcome.

#inc lude <stdio.h>
#inc lude <errno.h>

int *f(int errno) {
        if (errno==EINVAL) puts("EINVAL");
        return NULL;
}

int main() {
        f(f);
        return 0;
}

Solution:

errno.h defines: #define errno *(__errno_location()) 
When this is expanded in the parameter list, f is defined to get a function pointer parameter, named __errno_location. 
When this is expanded in the body, this function is called. 
Calling f with itself as a parameter leads to endless recursion.

Source Link
ugoren
  • 17.5k
  • 5
  • 52
  • 74
Loading