Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 21, 2025 at 05:47:20PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Friday, 16 May 2025 at 19:04:24 UTC, WhatMeWorry wrote: > > /+ SDL3 has a function > > bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); > > which has a Uint8 for one of its parameters. So I tr

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread Manfred Nowak via Digitalmars-d-learn
On Friday, 16 May 2025 at 19:04:24 UTC, WhatMeWorry wrote: [...] cast(uint8_t) b = cast(uint8_t) b + cast(uint8_t) 5; // [...] Somehow I don't get close enough to the underlying problem: ```d void main(){ ubyte a; a= cast( ubyte) ( a + 5); assert( a == 5); import core.stdc.stdint;

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread kdevel via Digitalmars-d-learn
On Friday, 16 May 2025 at 19:19:41 UTC, H. S. Teoh wrote: For example, how do you negate a ubyte? Mathematically this is only defined for 0 over the range of ubyte. Obviously, you can't do this: ``` ubyte a; a -=; ``` But writing it as `a = -a;` runs into the same error, for

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread WhatMeWorry via Digitalmars-d-learn
On Friday, 16 May 2025 at 19:04:24 UTC, WhatMeWorry wrote: /+ SDL3 has a function bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); which has a Uint8 for one of its parameters. So I try to use a ubyte +/ [...] So what would be best practice here? Declare an int, manually make

Re: Pragma msg goes out of memory when supplied with large data.

2025-05-21 Thread realhet via Digitalmars-d-learn
On Wednesday, 21 May 2025 at 14:40:21 UTC, realhet wrote: On Wednesday, 21 May 2025 at 14:00:56 UTC, realhet wrote: Small program to reproduce. I'm lucky: `pragma(msg, "Here comes the big data: ", data);` With this simple way I managed to put 16MB large data through it in no time. It was new t

Re: Pragma msg goes out of memory when supplied with large data.

2025-05-21 Thread realhet via Digitalmars-d-learn
On Wednesday, 21 May 2025 at 14:00:56 UTC, realhet wrote: Hi, Small program to reproduce. ```d import std; string doit(string data)() { static foreach(i; 0..256) { pragma(msg, i"Here goes lots of data: $(cast(ubyte[])data)".text); } return "dummy"; } static

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 16 May 2025 at 19:04:24 UTC, WhatMeWorry wrote: cast(uint8_t) b = cast(uint8_t) b + cast(uint8_t) 5; // onlineapp.d(19): Error: cannot implicitly convert expression

Pragma msg goes out of memory when supplied with large data.

2025-05-21 Thread realhet via Digitalmars-d-learn
Hi, I have a pragma(msg, xxx) statement where x is a byte array of 30KBytes. LDC2 produces the following symptom: It's memory usage goes slowly up to the maximum (20GB) then stops with out of memory error. The amount of used memory grows in an exponentially slowing rate. (I guess it's a rea

Re: shared library, function arguments order reversed?

2025-05-21 Thread kinke via Digitalmars-d-learn
On Wednesday, 21 May 2025 at 08:09:23 UTC, xoxo wrote: auto fn_test = cast(void function(int, int)) dlsym(lib, "test"); This is the problem - you're casting the address to an `extern(D)` function pointer. Use something like this: ``` alias Fn = extern(C) void function(int, int); auto fn_test

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread Dom DiSc via Digitalmars-d-learn
On Saturday, 17 May 2025 at 13:09:40 UTC, Jonathan M Davis wrote: On Friday, May 16, 2025 1:19:41 PM Mountain Daylight Time H. S. Teoh via Digitalmars-d-learn wrote: Welcome to your first encounter with why I hate D's narrow integer promotion rules. It's because C (and I'm pretty sure the CPU

shared library, function arguments order reversed?

2025-05-21 Thread xoxo via Digitalmars-d-learn
Hello, I am loading a library built with dmd on linux, but when I call other functions, the arguments order is reversed I understand calling convention from C/D is different, but shouldn't the compiler handle that automatically? if not, then that sounds like a bug? ```sh LD_LIBRARY_PATH=".