Re: ImportC GUID compilation problem with some Windows headers

2024-03-21 Thread Dave P. via Digitalmars-d-learn
On Thursday, 21 March 2024 at 18:19:58 UTC, Carl Sturtivant wrote: On Thursday, 21 March 2024 at 00:06:56 UTC, Carl Sturtivant wrote: ```C EXTERN_GUID(IID_IBlahBlahBlah, 0xabcdef12, 0x11d2, 0xab3a, 0xc0, 0x4f, [...] ); ``` Has anyone successfully compiled an EXTERN_GUID declaration like

Re: Running LDC on a recent MacOS

2023-06-16 Thread Dave P. via Digitalmars-d-learn
On Friday, 16 June 2023 at 16:25:35 UTC, Dmitry Olshansky wrote: On Friday, 16 June 2023 at 16:14:19 UTC, Steven Schveighoffer wrote: On 6/16/23 11:56 AM, Dmitry Olshansky wrote: Any advice from MacOS users? Yep. Go into settings, then privacy and security. Make sure "App store and

Re: ImportC std support

2021-12-12 Thread Dave P. via Digitalmars-d-learn
On Sunday, 12 December 2021 at 07:40:10 UTC, ManKey wrote: On Saturday, 11 December 2021 at 22:28:16 UTC, forkit wrote: On Saturday, 11 December 2021 at 21:42:49 UTC, ManKey wrote: umm... the site has search function you know ;-) Dude, you see, it doesn't say anything about it. It says a

Re: How to check for overflow when adding/multiplying numbers?

2021-12-06 Thread Dave P. via Digitalmars-d-learn
On Monday, 6 December 2021 at 18:38:37 UTC, Ola Fosheim Grøstad wrote: On Monday, 6 December 2021 at 17:46:35 UTC, Dave P. wrote: I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See

How to check for overflow when adding/multiplying numbers?

2021-12-06 Thread Dave P. via Digitalmars-d-learn
I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See [here](https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html) for reference. Is there a D equivalent?

Re: Can we use "ImportC" used yet?

2021-10-22 Thread Dave P. via Digitalmars-d-learn
On Friday, 22 October 2021 at 06:11:35 UTC, data pulverizer wrote: On Thursday, 21 October 2021 at 23:06:18 UTC, jfondren wrote: [...] I've double-checked and the types names are fine in translated C file. [...] I think you ran into this

Casting between structs of the same size is treated as a bit cast?

2021-10-19 Thread Dave P. via Digitalmars-d-learn
I am confused on how casting structs works. According to point 9 of https://dlang.org/spec/expression.html#CastExpression: Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: ```d S(v) ``` However, the following program compiles and the resulting

Re: Can I output strings using core.stdc.stdio?

2020-12-22 Thread Dave P. via Digitalmars-d-learn
On Tuesday, 22 December 2020 at 21:37:23 UTC, Godnyx wrote: On Tuesday, 22 December 2020 at 21:28:10 UTC, Dave P. wrote: On Tuesday, 22 December 2020 at 21:10:59 UTC, Godnyx wrote: [...] Lol. Actually I just don't want to use Phobos and trying to stay on core. Unfortunately, my variable

Re: Can I output strings using core.stdc.stdio?

2020-12-22 Thread Dave P. via Digitalmars-d-learn
On Tuesday, 22 December 2020 at 21:10:59 UTC, Godnyx wrote: Is there a way? If not then how std.stdio does it? I assume you’re asking this because you don’t have access to std.stdio (such as using betterC). The way to do it is to use the %.*s specifier in printf. For example: void

Re: Floating point values in structs.

2020-12-22 Thread Dave P. via Digitalmars-d-learn
On Tuesday, 22 December 2020 at 18:10:22 UTC, Dukc wrote: On Friday, 18 December 2020 at 16:18:12 UTC, Dave P. wrote: [...] Honestly, I just want all bits zero. I don’t work with any platforms where null is not 0 and all-zero-bits aggregates can be efficiently represented in static storage.

Re: Floating point values in structs.

2020-12-18 Thread Dave P. via Digitalmars-d-learn
On Friday, 18 December 2020 at 16:23:20 UTC, Adam D. Ruppe wrote: On Friday, 18 December 2020 at 16:18:12 UTC, Dave P. wrote: Is the proper solution to change the struct definition to: yeah that's the best option right now A bit of a pain when porting, but alright. I find the setting

Floating point values in structs.

2020-12-18 Thread Dave P. via Digitalmars-d-learn
I got burned by behavior of struct initialization I didn’t anticipate last night. Consider a struct: struct Foo { float x, y, z; int a, b, c; } My source C code was initializing it by doing something like: Foo f = {.y = 3} Which uses the C behavior that all the other fields will be

Re: Getting the source text of an expression

2020-12-17 Thread Dave P. via Digitalmars-d-learn
On Thursday, 17 December 2020 at 21:24:40 UTC, FreeSlave wrote: On Thursday, 17 December 2020 at 19:45:38 UTC, Dave P. wrote: [...] Something like that? import std.stdio; void print_int(alias n)() { writeln(n.stringof~"=", n); } void main() { int x = 42; print_int!(x);

Getting the source text of an expression

2020-12-17 Thread Dave P. via Digitalmars-d-learn
In C, you can use a macro to get the source text of an expression as a string. For example #include #define PRINT_INT(x) printf(#x " = %d\n", x) int main(){ // prints "3 = 3" PRINT_INT(3); int x = 4; // prints "x = 4" PRINT_INT(x); #define FOO 5 // prints "FOO = 5"

Re: extern(C) and name mangling

2020-12-16 Thread Dave P. via Digitalmars-d-learn
On Wednesday, 16 December 2020 at 06:46:42 UTC, Jacob Carlborg wrote: On Wednesday, 16 December 2020 at 04:17:13 UTC, Mike Parker wrote: However, the D calling convention is defined to be identical to the C calling convention on the host system for everything except Windows x86. That's

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Dave P. via Digitalmars-d-learn
On Wednesday, 16 December 2020 at 03:50:07 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 19:02:34 UTC, Dave P. wrote: On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: [...] Based on you requirement to use

Re: extern(C) and name mangling

2020-12-15 Thread Dave P. via Digitalmars-d-learn
On Wednesday, 16 December 2020 at 04:17:13 UTC, Mike Parker wrote: On Tuesday, 15 December 2020 at 22:04:12 UTC, Dave P. wrote: [...] Mangling does not play any role in passing and calling function pointers between D and C. It only plays a role in linking and loading. You can declare

extern(C) and name mangling

2020-12-15 Thread Dave P. via Digitalmars-d-learn
I can’t find this in the spec, but from experimentation it seems like extern(C) only affects name mangling of functions at the top level scope. Thus extern(C) function templates would be mangled differently, but still use the C calling convention. Is this right? I want to pass some templated

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Dave P. via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 19:45:50 UTC, Q. Schroll wrote: On Sunday, 13 December 2020 at 19:02:34 UTC, Dave P. wrote: On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward

Re: UFCS functions with both pointers and refs

2020-12-13 Thread Dave P. via Digitalmars-d-learn
On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward to the other for more complicated functions? For free functions, yes. Is there any way to write the function as a

UFCS functions with both pointers and refs

2020-12-13 Thread Dave P. via Digitalmars-d-learn
If I define a method on a type, then I can call it both through a pointer and through a reference and the compiler does the right thing. Eg: struct Foo { int x; void fooey(){ x++; } void report(){ printf("%d\n", x); } } int main(){ Foo f; f.fooey;

Re: Static on free functions

2020-12-07 Thread Dave P. via Digitalmars-d-learn
On Monday, 7 December 2020 at 17:07:20 UTC, Adam D. Ruppe wrote: On Monday, 7 December 2020 at 17:01:45 UTC, Dave P. wrote: Does `static` on a free function definition do anything? Nope, D allows a lot of useless attributes so it doesn't complain if you do certain things out of habit (or it

Static on free functions

2020-12-07 Thread Dave P. via Digitalmars-d-learn
Does `static` on a free function definition do anything? I know the meaning of it in C, but I can’t find an equivalent definition (or any definition of it at all) when applied to free functions in the spec. Are the two below any different or is it just for ease of porting from C? static