Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward declarations #85

Open
bafto opened this issue Jul 26, 2024 · 0 comments
Open

Forward declarations #85

bafto opened this issue Jul 26, 2024 · 0 comments
Labels
Typ: Neues Feature Neues Feature

Comments

@bafto
Copy link
Member

bafto commented Jul 26, 2024

Das Problem

DDP hat das Problem, dass eine Funktion definiert sein muss bevor man sie aufrufen kann, da ihre Aliase sonst nicht bekannt sind.
Das selbe Problem gibt es in C und C++:

int foo() {
    // error bar undefined
    return bar();
}
int bar() {
    return 1;
}

Die einfachste Lösung ist, die Funktionen einfach andersherum zu definieren. Das Funktioniert aber nicht wenn sie sich gegenseitig aufrufen:

int i = 10;
int foo() {
    // error bar undefined
    return i != 0 ? bar() : 1;
}

int bar() {
    i--;
    return foo();
}

In diesem Fall ist die Lösung eine forward-declaration:

int bar();
int i = 10;
int foo() {
    return i != 0 ? bar() : 1;
}

int bar() {
    i--;
    return foo();
}

Das bräuchte es auch in DDP um solche Konstrukte möglich zu machen.

Syntax Vorschlag

Die öffentliche Funktion bar mit den Parametern a, b und c vom Typ Zahl, Kommazahl und Text Referenz wird eine Zahl zurück geben und die Aliase 
"bar <a> <b> <c>", "<a> bar <b> <c>" und "barbara <a> bar <b> <c>" besitzen.

Solche Deklarationen müssen mit der späteren Definition eins-zu-eins übereinstimmen, bis auf die Aliase.
Ich würde sagen es dürfen Aliase weggelassen werden, falls man in der forward-declaration nicht alle braucht.

Außerdem müssen alle Funktionen die man deklariert auch im selben Modul definiert werden.

@bafto bafto added the Typ: Neues Feature Neues Feature label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typ: Neues Feature Neues Feature
Projects
None yet
Development

No branches or pull requests

1 participant