Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-06 Thread Rubn via Digitalmars-d-learn
On Friday, 4 May 2018 at 07:57:26 UTC, Uknown wrote: On Friday, 4 May 2018 at 07:49:02 UTC, Robert M. Münch wrote: I have a static C++ and can't make it to get a correct binding for one function: DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class

Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Uknown via Digitalmars-d-learn
On Friday, 4 May 2018 at 07:49:02 UTC, Robert M. Münch wrote: I have a static C++ and can't make it to get a correct binding for one function: DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64 const) __ptr64

C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Robert M. Münch via Digitalmars-d-learn
I have a static C++ and can't make it to get a correct binding for one function: DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64 const) __ptr64 LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 22:23:47 UTC, Cecil Ward wrote: say in C I have a function with a pointer argument foo( const sometype_t * p ) [...] That's the secret - I didn't know about the const (T) * thing - I would never have discovered that ! Many thanks, the missing piece to the

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-14 Thread ag0aep6g via Digitalmars-d-learn
a mutable pointer from a const one: const int* c; const(int)* m = c; /* no problem */ The target of the pointer just has to remain `const`. [...] There probably is a tool somewhere to safely create a modifiable object based on a const object but I'm not sure where to look. Generally

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 14, 2018 22:23:47 Cecil Ward via Digitalmars-d-learn wrote: > say in C I have a function with a pointer argument > foo( const sometype_t * p ) > > I have asked about this D nightmare before. Using the same > pattern in D or the in argument qualifier as far as I can see

Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-14 Thread Cecil Ward via Digitalmars-d-learn
say in C I have a function with a pointer argument foo( const sometype_t * p ) I have asked about this D nightmare before. Using the same pattern in D or the in argument qualifier as far as I can see the value of the pointer is then itself effectively locked made constant. Without

Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn
Hi, I like to print the strings from a C function that returns const(dchar*), but I can't make the conversion to dstring. I can convert vice versa by: dstring text = Hello; const(dchar)* str = toUTFz!(const(dchar)*)(text); // passing it to C function prints Hello However, I don't have the

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 24 Jun 2014 13:37:41 -0400, Danyal Zia catofdan...@yahoo.com wrote: Hi, I like to print the strings from a C function that returns const(dchar*), but I can't make the conversion to dstring. I can convert vice versa by: dstring text = Hello; const(dchar)* str =

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: const(dchar *)x = ...; // assuming 0 terminated dstring text = x[0..x.strlen].idup; -Steve const(dchar)* x = Hello\0; dstring text = x[0..x.strlen].idup; writeln(text); Error: no property 'strlen' for type 'const(dchar)*'

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: // assuming 0 terminated dstring text = x[0..x.strlen].idup; strlen is only defined for char, not dchar: https://github.com/D-Programming-Language/druntime/blob/master/src/core/stdc/string.d#L44

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 18:17:07 UTC, Danyal Zia wrote: On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: const(dchar *)x = ...; // assuming 0 terminated dstring text = x[0..x.strlen].idup; -Steve const(dchar)* x = Hello\0; dstring text = x[0..x.strlen].idup;

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Jun 2014 18:17:06 +, Danyal Zia wrote: On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: const(dchar *)x = ...; // assuming 0 terminated dstring text = x[0..x.strlen].idup; -Steve const(dchar)* x = Hello\0; dstring text = x[0..x.strlen].idup;

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 18:34:31 UTC, Chris Cain wrote: You can do what he said, but you'll have to write your own strlen function: something like: size_t strlen(in dchar* s) pure @system nothrow { size_t pos = 0; dchar term = '\0'; while(s[pos] != term)

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 24 Jun 2014 14:28:58 -0400, Chris Cain zsh...@gmail.com wrote: On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: // assuming 0 terminated dstring text = x[0..x.strlen].idup; strlen is only defined for char, not dchar:

Re: Translating C const

2012-05-27 Thread Jacob Carlborg
That seems like a good approach, since then you're not marking things as const in D that C would consider mutable and therefore be likely to be altered, breaking D's guarantees. It does make me think that it could be valuable to include a comment with the original declaration though (at least

Re: Translating C const

2012-05-26 Thread Jacob Carlborg
creating. You'll probably have to go with what is _least_ likely to cause bugs and then let the programmer adjust it as needed. - Jonathan M Davis What do you think about translating the C const to D where possible and then just leave it mutable in all other cases. Then assuming the C code

Re: Translating C const

2012-05-26 Thread Jonathan M Davis
called, which naturally doesn't go well with a tool like you're creating. You'll probably have to go with what is _least_ likely to cause bugs and then let the programmer adjust it as needed. - Jonathan M Davis What do you think about translating the C const to D where possible

Re: Translating C const

2012-05-25 Thread Jonathan M Davis
On Wednesday, May 16, 2012 10:24:55 Jacob Carlborg wrote: On 2012-05-16 09:00, Jonathan M Davis wrote: Probably true. But also, if you're talking about a const pointer to a mutable value, the constness of the pointer is actually irrelevant to the caller. The pointer will be copied when the

Re: Translating C const

2012-05-16 Thread Jacob Carlborg
On 2012-05-16 07:35, Simen Kjaeraas wrote: That depends. Will the contents be modified? I have no idea. I'm working on a tool for automatically translating C headers. I was thinking since I don't know, I better not add any promises that is not kept. -- /Jacob Carlborg

Re: Translating C const

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 08:50:27 Jacob Carlborg wrote: On 2012-05-16 07:35, Simen Kjaeraas wrote: That depends. Will the contents be modified? I have no idea. I'm working on a tool for automatically translating C headers. I was thinking since I don't know, I better not add any promises

Re: Translating C const

2012-05-16 Thread Jacob Carlborg
On 2012-05-16 09:00, Jonathan M Davis wrote: Probably true. But also, if you're talking about a const pointer to a mutable value, the constness of the pointer is actually irrelevant to the caller. The pointer will be copied when the function is called, so it doesn't matter on whit whether the

Re: Translating C const

2012-05-16 Thread Simon
On 16/05/2012 09:24, Jacob Carlborg wrote: On 2012-05-16 09:00, Jonathan M Davis wrote: Probably true. But also, if you're talking about a const pointer to a mutable value, the constness of the pointer is actually irrelevant to the caller. The pointer will be copied when the function is

Translating C const

2012-05-15 Thread Jacob Carlborg
I'm trying to figuring out how to translate const in C to D. I have these examples: const int * a; int * const b; const int * const c; const int * const * d; Which I think should be translated like this: const(int)* a; const int* c; const(int*)* d; But I don't know how to translate b. I

Re: Translating C const

2012-05-15 Thread Ali Çehreli
On 05/15/2012 12:36 PM, Jacob Carlborg wrote: I'm trying to figuring out how to translate const in C to D. I have these examples: const int * a; int * const b; const int * const c; const int * const * d; Which I think should be translated like this: const(int)* a; const int* c; const(int*)* d

Re: Translating C const

2012-05-15 Thread Jacob Carlborg
On 2012-05-15 21:50, Ali Çehreli wrote: Not possible in D. D's const is transitive. If b is const, then what it points to is also const. Ali Then it would be best to not declare that as const? -- /Jacob Carlborg

Re: Translating C const

2012-05-15 Thread Simen Kjaeraas
On Tue, 15 May 2012 21:58:46 +0200, Jacob Carlborg d...@me.com wrote: On 2012-05-15 21:50, Ali Çehreli wrote: Not possible in D. D's const is transitive. If b is const, then what it points to is also const. Ali Then it would be best to not declare that as const? That depends. Will the

Re: C const

2011-03-05 Thread Simen kjaeraas
Jesse Phillips jessekphillip...@gmail.com wrote: simendsjo Wrote: On 04.03.2011 23:10, Jesse Phillips wrote: Remember that const/immutable, and other attributes/properties aren't going to change the ABI so dropping them will be safer then leaving them. Thanks. Does this apply to all

Re: C const

2011-03-05 Thread Jesse Phillips
Simen kjaeraas Wrote: Hopefully I'm not wrong on this, but you should even be able to change the type as long as the size is the same. So instead of int you could use uint or byte[8]... granted the library will still interpret it as int. And of course that is assuming you are on a

C const

2011-03-04 Thread simendsjo
I'm not quite sure how to wrap c's const. This page, http://www.digitalmars.com/d/2.0/htomodule.html, says: D has const as a type modifier. void foo(const int *p, char *const q); becomes: void foo(const int* p, const char* q); But D's const is transitive - there are no const

Re: C const

2011-03-04 Thread simendsjo
On 04.03.2011 23:10, Jesse Phillips wrote: simendsjo Wrote: So all const modifiers should be dropped everywhere..? And should the const be dropped here? struct somestruct { const struct otherstruct; } All in all the real answer comes down to, is the data modified. Since C makes no

Re: C const

2011-03-04 Thread Jesse Phillips
simendsjo Wrote: On 04.03.2011 23:10, Jesse Phillips wrote: Remember that const/immutable, and other attributes/properties aren't going to change the ABI so dropping them will be safer then leaving them. Thanks. Does this apply to all uses of const, or just complex members? Hopefully