Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 10:51:48 AM MDT Andy Valencia via Digitalmars-d- learn wrote: > On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: > > ... > > But what exactly static means varies based on the context. > > Thank you for the list! But none of those appear to apply to a > fu

Re: static functions?

2024-03-11 Thread user1234 via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:51:48 UTC, Andy Valencia wrote: On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: ... But what exactly static means varies based on the context. Thank you for the list! But none of those appear to apply to a function defined in the outermost sco

Re: static functions?

2024-03-11 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: ... But what exactly static means varies based on the context. Thank you for the list! But none of those appear to apply to a function defined in the outermost scope of the module. Is static accepted here--but has no actual e

Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 9:56:24 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > Leveraging my knowledge of C, I assumed a "static" function would > be hidden outside of its own source file. I can't find any > statement about the semantics of a static function in the > documentation, and i

static functions?

2024-03-11 Thread Andy Valencia via Digitalmars-d-learn
Leveraging my knowledge of C, I assumed a "static" function would be hidden outside of its own source file. I can't find any statement about the semantics of a static function in the documentation, and in practice (ldc2 on Linux) it doesn't hide the function? file tst.d: import std.stdio :

Re: C style 'static' functions

2017-07-19 Thread Johannes Pfau via Digitalmars-d-learn
Am Wed, 19 Jul 2017 19:18:03 + schrieb Petar Kirov [ZombineDev] : > On Wednesday, 19 July 2017 at 18:49:32 UTC, Johannes Pfau wrote: > > > > Can you explain why _object-level visibility_ would matter in > > this case? > > (I'm sure you have more experience with shared libraries than me, >

Re: C style 'static' functions

2017-07-19 Thread via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 18:49:32 UTC, Johannes Pfau wrote: Can you explain why _object-level visibility_ would matter in this case? (I'm sure you have more experience with shared libraries than me, so correct me if I'm wrong) We can't do attribute inference for exported functions bec

Re: C style 'static' functions

2017-07-19 Thread Johannes Pfau via Digitalmars-d-learn
Am Wed, 19 Jul 2017 17:37:48 + schrieb Kagamin : > On Wednesday, 19 July 2017 at 15:28:50 UTC, Steven Schveighoffer > wrote: > > I'm not so sure of that. Private functions still generate > > symbols. I think in C, there is no symbol (at least in the > > object

Re: C style 'static' functions

2017-07-19 Thread Johannes Pfau via Digitalmars-d-learn
tended semantics. I believe that with DIP45, > only functions and global variables annotated with the export > storage class would necessary have externally visible symbols. > Yes, this DIP is the solution to have true C-like static functions. Non-exported private will then be

Re: C style 'static' functions

2017-07-19 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 15:28:50 UTC, Steven Schveighoffer wrote: I'm not so sure of that. Private functions still generate symbols. I think in C, there is no symbol (at least in the object file) for static functions or variables. They generate hidden symbols. That's j

Re: C style 'static' functions

2017-07-19 Thread via Digitalmars-d-learn
least in the object file) for static functions or variables. You could still call a private function in a D module via the mangled name I believe. -Steve Note: not 100% sure of all this, but this is always the way I've looked at it. You're probably right about the current implement

Re: C style 'static' functions

2017-07-19 Thread Johannes Pfau via Digitalmars-d-learn
least in the object file) for static functions or variables. You could still call a private function in a D module via the mangled name I believe. -Steve Note: not 100% sure of all this, but this is always the way I've looked at it. That's correct. We unfortunately can't d

Re: C style 'static' functions

2017-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
This is in contrast with C++, Java, C# where private members are visible only the class they are defined in. I'm not so sure of that. Private functions still generate symbols. I think in C, there is no symbol (at least in the object file) for static functions or variables. You c

Re: C style 'static' functions

2017-07-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-07-19 14:11, John Burton wrote: Hmm it turns out this machine has 2.0.65 on which is fairly ancient. I'd not realized this machine had not been updated. Sorry for wasting everyones' time if that's so, and thanks for the help. I suspected something like this :). Nice to hear that you

Re: C style 'static' functions

2017-07-19 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 12:16:46 UTC, John Burton wrote: Looks like it's https://wiki.dlang.org/DIP22 that changed this Specifically, it was fixed in DMD 2.071.0 released in April of last year: http://dlang.org/changelog/2.071.0.html#dip22

Re: C style 'static' functions

2017-07-19 Thread via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 12:11:38 UTC, John Burton wrote: On Wednesday, 19 July 2017 at 12:05:09 UTC, Kagamin wrote: Try a newer compiler, this was fixed recently. Hmm it turns out this machine has 2.0.65 on which is fairly ancient. I'd not realized this machine had not been updated. S

Re: C style 'static' functions

2017-07-19 Thread John Burton via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 12:15:05 UTC, Mike Parker wrote: On Wednesday, 19 July 2017 at 12:11:38 UTC, John Burton wrote: On Wednesday, 19 July 2017 at 12:05:09 UTC, Kagamin wrote: Try a newer compiler, this was fixed recently. Hmm it turns out this machine has 2.0.65 on which is fairly

Re: C style 'static' functions

2017-07-19 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 12:11:38 UTC, John Burton wrote: On Wednesday, 19 July 2017 at 12:05:09 UTC, Kagamin wrote: Try a newer compiler, this was fixed recently. Hmm it turns out this machine has 2.0.65 on which is fairly ancient. I'd not realized this machine had not been updated. S

Re: C style 'static' functions

2017-07-19 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 11:52:09 UTC, John Burton wrote: lib1.d private void init() { // init function used only as an implementation detail } void mything() { init(); } lib2.d - void init() { // init function meant to be used as part of the module inte

Re: C style 'static' functions

2017-07-19 Thread John Burton via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 12:05:09 UTC, Kagamin wrote: Try a newer compiler, this was fixed recently. Hmm it turns out this machine has 2.0.65 on which is fairly ancient. I'd not realized this machine had not been updated. Sorry for wasting everyones' time if that's so, and thanks for t

Re: C style 'static' functions

2017-07-19 Thread Kagamin via Digitalmars-d-learn
Try a newer compiler, this was fixed recently.

Re: C style 'static' functions

2017-07-19 Thread John Burton via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 11:31:32 UTC, Jacob Carlborg wrote: On 2017-07-19 09:22, John Burton wrote: In C I can declare a function 'static' and it's only visible from within that implementation file. So I can have a static function 'test' in code1.c and another non static function 'test'

Re: C style 'static' functions

2017-07-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-07-19 09:22, John Burton wrote: In C I can declare a function 'static' and it's only visible from within that implementation file. So I can have a static function 'test' in code1.c and another non static function 'test' in utils.c and assuming a suitable prototype I can use 'test' in my

Re: C style 'static' functions

2017-07-19 Thread EnterYourNameHere via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 07:22:48 UTC, John Burton wrote: In C I can declare a function 'static' and it's only visible from within that implementation file. So I can have a static function 'test' in code1.c and another non static function 'test' in utils.c and assuming a suitable prototype

Re: C style 'static' functions

2017-07-19 Thread John Burton via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 07:51:11 UTC, Gary Willoughby wrote: On Wednesday, 19 July 2017 at 07:22:48 UTC, John Burton wrote: In C++ I could use static or an anonymous namespace for implementation functions, but there doesn't seem to be anything similar in D. Is there any way to achieve wha

Re: C style 'static' functions

2017-07-19 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 07:22:48 UTC, John Burton wrote: In C++ I could use static or an anonymous namespace for implementation functions, but there doesn't seem to be anything similar in D. Is there any way to achieve what I want in D (Private implementation functions) Try the package

C style 'static' functions

2017-07-19 Thread John Burton via Digitalmars-d-learn
In C I can declare a function 'static' and it's only visible from within that implementation file. So I can have a static function 'test' in code1.c and another non static function 'test' in utils.c and assuming a suitable prototype I can use 'test' in my program and the one in code1.c will not

Re: static functions associated with enums

2013-03-21 Thread Ali Çehreli
On 03/21/2013 01:34 PM, Dan wrote: > Json serializeToJson(T)(T value) { > ... > static if( __traits(compiles, value = T.fromJson(value.toJson())) ){ It looks like fromJson must be a static member function because the condition is written in a way that fromJson is called on the type itself. (I

static functions associated with enums

2013-03-21 Thread Dan
I have an enum, say: enum AssetCategory { Investment, PrimaryResidence, FamilyProperty, FinancialInstrument } and I have functions that convert to/from strings to be used in Json (via vibe json). The vibe wants to call out to user supplied toJson/fromJson if both functions are provided

Re: static functions?

2012-05-20 Thread Mike Parker
On 5/21/2012 6:32 AM, jerro wrote: On Sunday, 20 May 2012 at 21:19:14 UTC, p0xel wrote: This seems to work when the class is in the same file as main(), but if I move it to it's own file and use "import foo" it errors. What am I missing? When you write "import foo;" and then foo.bar, the compi

Re: static functions?

2012-05-20 Thread jerro
On Sunday, 20 May 2012 at 21:19:14 UTC, p0xel wrote: This seems to work when the class is in the same file as main(), but if I move it to it's own file and use "import foo" it errors. What am I missing? When you write "import foo;" and then foo.bar, the compiler thinks that you a referring to

Re: static functions?

2012-05-20 Thread p0xel
This seems to work when the class is in the same file as main(), but if I move it to it's own file and use "import foo" it errors. What am I missing?

static functions?

2012-05-20 Thread p0xel
I pretty sure I'm an idiot. [code] class foo { public static int bar() { return 0; } } [/code] How do I call bar() without creating an instance of foo? foo.bar() results in "Error: undefined identifier 'bar'" I'm having a really hard time finding anything relat

Re: Static functions in immutable types...

2009-12-08 Thread Michal Minich
tion as a normal function. >>> This is why the OP said they "don't make sense" Although his >>> statement really should be "immutable static functions don't make >>> sense", not "static functions in immutable types don't make se

Re: Static functions in immutable types...

2009-12-08 Thread Steven Schveighoffer
em I see is in definition of what const or immutable member function means: from D specs: "Immutable member functions are guaranteed that the object and anything referred to by the this reference is immutable." Which applies both to instance and s static functions. I think the abo

Re: Static functions in immutable types...

2009-12-08 Thread Michal Minich
r function means: from D specs: "Immutable member functions are guaranteed that the object and anything referred to by the this reference is immutable." Which applies both to instance and s static functions. I think the above definition should apply only to instance functions. Static const

Re: Static functions in immutable types...

2009-12-08 Thread Steven Schveighoffer
ce is immutable." Which applies both to instance and s static functions. I think the above definition should apply only to instance functions. Static const or immutable functions should be defined as: Immutable static member functions are guaranteed that the static variables of object and

Re: Static functions in immutable types...

2009-12-08 Thread Michal Minich
nce is immutable." Which applies both to instance and s static functions. I think the above definition should apply only to instance functions. Static const or immutable functions should be defined as: Immutable static member functions are guaranteed that the static variables of object and

Re: Static functions in immutable types...

2009-12-07 Thread Tomek Sowiński
mutable." Which applies both to instance and s static functions. I think the above definition should apply only to instance functions. Static const or immutable functions should be defined as: Immutable static member functions are guaranteed that the static variables of object and

Re: Static functions in immutable types...

2009-12-07 Thread Michal Minich
every its member so. The problem I see is in definition of what const or immutable member function means: from D specs: "Immutable member functions are guaranteed that the object and anything referred to by the this reference is immutable." Which applies both to instance and s stati

Static functions in immutable types...

2009-12-06 Thread Tomek Sowiński
... don't make sense. So is there a reason why they aren't excluded from the "everything in an immutable is immutable" rule? Tomek