| Thread overview | |||||
|---|---|---|---|---|---|
|
January 08, 2009 Purity and C functions | ||||
|---|---|---|---|---|
| ||||
If someone wants to call C code from a pure D function, how can this be done? How does one tell DMD that the C function is, in fact, pure? | ||||
January 08, 2009 Re: Purity and C functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | On Thu, 08 Jan 2009 06:00:35 +0300, dsimcha <dsimcha@yahoo.com> wrote:
> If someone wants to call C code from a pure D function, how can this be done?
> How does one tell DMD that the C function is, in fact, pure?
Purite can't be checked on extern functions. It these cases DMD should rely on programmer.
For example, you could define strstr as follows:
extern(C) pure invariant(char)* strstr(invariant(char)* str1, invariant(char)* str2);
This way it is truly pure.
I wonder what results you may get using "extern(C) pure int rand();" though. :p
| |||
January 08, 2009 Re: Purity and C functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin wrote:
> I wonder what results you may get using "extern(C) pure int rand();" though. :p
If you declare as pure functions that are impure, you'll get undefined behavior.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply