Jump to page: 1 2
Thread overview
Static function at module level
Aug 18, 2014
Phil Lavoie
Aug 18, 2014
Jonathan M Davis
Aug 18, 2014
Phil Lavoie
Aug 18, 2014
ketmar
Aug 18, 2014
bearophile
Aug 18, 2014
H. S. Teoh
Aug 18, 2014
bearophile
Aug 18, 2014
Phil Lavoie
Aug 18, 2014
Phil Lavoie
Aug 18, 2014
ketmar
Aug 18, 2014
Phil Lavoie
Aug 18, 2014
ketmar
August 18, 2014
Ok, so after years of D usage I just noticed that this is valid D (compiles anyways):

static void myFunc() {}

What is a static function at module level exactly? In C, that means private, in D, that means ___________?

Thanks,
Phil
August 18, 2014
On Mon, 18 Aug 2014 01:32:40 +0000
Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> Ok, so after years of D usage I just noticed that this is valid D
> (compiles anyways):
>
> static void myFunc() {}
>
> What is a static function at module level exactly? In C, that means private, in D, that means ___________?

I'm pretty sure that it means nothing. It's just one of those cases where an attribute is ignored, because it doesn't apply rather than resulting in an error.

- Jonathan M Davis
August 18, 2014
On Mon, 18 Aug 2014 01:32:40 +0000
Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> What is a static function at module level exactly? In C, that means private, in D, that means ___________?
nothing. static attribute for free function has no special meaning. but other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?


August 18, 2014
ketmar:

> other function declarations (methods, nested functions) accepts
> 'static', so why free functions shouldn't?

For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head.

Bye,
bearophile
August 18, 2014
On Mon, Aug 18, 2014 at 06:46:02AM +0000, bearophile via Digitalmars-d-learn wrote:
> ketmar:
> 
> >other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?
> 
> For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head.
[...]

Is there a bug filed for this?


T

-- 
Век живи - век учись. А дураком помрёшь.
August 18, 2014
H. S. Teoh:

> Is there a bug filed for this?

Probably there is. But I stopped filing similar bugs because they seem to have a very low priority.

Bye,
bearophile
August 18, 2014
On Monday, 18 August 2014 at 05:29:53 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Mon, 18 Aug 2014 01:32:40 +0000
> Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
> wrote:
>
>> Ok, so after years of D usage I just noticed that this is valid D
>> (compiles anyways):
>>
>> static void myFunc() {}
>>
>> What is a static function at module level exactly? In C, that
>> means private, in D, that means ___________?
>
> I'm pretty sure that it means nothing. It's just one of those cases where an
> attribute is ignored, because it doesn't apply rather than resulting in an
> error.
>
> - Jonathan M Davis

All right thanks!
August 18, 2014
On Monday, 18 August 2014 at 06:46:03 UTC, bearophile wrote:
> ketmar:
>
>> other function declarations (methods, nested functions) accepts
>> 'static', so why free functions shouldn't?
>
> For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head.
>
> Bye,
> bearophile

Agreed. I was misled for a minute. I don't think it should compile.

August 18, 2014
On Monday, 18 August 2014 at 14:23:47 UTC, bearophile wrote:
> H. S. Teoh:
>
>> Is there a bug filed for this?
>
> Probably there is. But I stopped filing similar bugs because they seem to have a very low priority.
>
> Bye,
> bearophile

I looked around for it but didn't find it. I filed this one: https://issues.dlang.org/show_bug.cgi?id=13322

As you'll see, every type of module level declaration accepts static.
static int x;
static void myFunc(){}
static interface MyInterface{}
static class MyClass{}
static struct MyStruct{}
static template myTemplate{}

And maybe I am missing some.
August 18, 2014
On Mon, 18 Aug 2014 06:46:02 +0000
bearophile via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> accepting useless code confuses newbies
i think that i'm not really a newbie now ;-), but i'm still used to declare various private module functions and variables as 'static'. yes, sometimes this confuses me (as to "do i need to make this sta... ah, scrap that, it's D!"), but sometimes this is handy. why? i'm still have to use C sometimes, and i'm writing 'static' automatically. having compiler to accept it for anything high-level saves me one regexp search-and-replace. ;-)


« First   ‹ Prev
1 2