digitalmars.D.learn - Rhyme and reason for function annotations?
- Andy Valencia (15/15) Nov 03 2024 A function can be described as, say, private, or pure, or @nogc.
- Jonathan M Davis (17/30) Nov 03 2024 There really isn't one. Function attributes originally didn't have @ on
A function can be described as, say, private, or pure, or nogc.
When does an annotation have an ' '? Also, a function can be
annotated
int myfunc(char *arg) pure {
}
Although I find:
pure int myfunc(char *arg) {
}
Also works. So what annotations have 's, and when do they go
with the function declaration, and when do they go after the
argument declaration?
I don't need an exhaustive list, I'm much more interested in the
underlying philosophy which assigns what to where.
Thank you!
Andy Valencia
Nov 03 2024
On Sunday, November 3, 2024 5:01:20 PM MST Andy Valencia via Digitalmars-d-
learn wrote:
A function can be described as, say, private, or pure, or nogc.
When does an annotation have an ' '? Also, a function can be
annotated
int myfunc(char *arg) pure {
}
Although I find:
pure int myfunc(char *arg) {
}
Also works. So what annotations have 's, and when do they go
with the function declaration, and when do they go after the
argument declaration?
I don't need an exhaustive list, I'm much more interested in the
underlying philosophy which assigns what to where.
There really isn't one. Function attributes originally didn't have on
them, but newer ones got an to avoid adding new keywords.
And in general, you can put function attributes on either side of a
function, and it doesn't matter. It's a matter of preference. The main
gotcha there is that if an attribute could affect either the function or the
return type, then it's going to affect the function if you don't use parens,
e.g.
struct S
{
const int foo() { ... }
}
is going to make foo a const member function even though it looks like
you're saying that you want const int. To get that, you need
const(int) foo() { ... }
- Jonathan M Davis
Nov 03 2024








Jonathan M Davis <newsgroup.d jmdavisprog.com>