digitalmars.D.learn - Equivalent to nullptr
- Leonardo (24/24) May 03 2017 I was trying to use Derelict-SDL2 library, and the tutorial do
- Adam D. Ruppe (2/3) May 03 2017 Does it work if you just use `null` ?
- Leonardo (13/16) May 03 2017 No.
- Stanislav Blinov (7/24) May 03 2017 Ahh, looks to be a bug in DerelictSDL2. null will work for that
- Stanislav Blinov (5/15) May 03 2017 In the meantime, you can get around the issue by redeclaring the
- Leonardo (2/19) May 16 2017 Thank you.
I was trying to use Derelict-SDL2 library, and the tutorial do
this code below, as C++ code has nullptr word. How I use this?
---------------------------------
struct Ball
{
SDL_Rect bbox = {0, 0, 100, 100};
SDL_Point vel = {1, 1};
}
---------------------------------
case SDL_MOUSEBUTTONDOWN:
{
SDL_Point mousePos = {event.button.x, event.button.y};
if(event.button.button == SDL_BUTTON_LEFT &&
SDL_EnclosePoints(&mousePos, 1, &ball.bbox, nullptr) )
{
SDL_Log("CLICK");
if(abs(ball.vel.x) < 32)
{
ball.vel.x *= 2;
ball.vel.y *= 2;
}
}
break;
}
May 03 2017
On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:nullptr word. How I use this?Does it work if you just use `null` ?
May 03 2017
On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote:On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:No. First I got: source/app.d(45,69): Error: expression (*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null) of type void does not have a boolean value then I change to: event.button.button == SDL_BUTTON_LEFT && SDL_TRUE == SDL_EnclosePoints(&mousePos, 1, &ball.bbox, null) and got: source/app.d(45,81): Error: void has no value source/app.d(45,52): Error: incompatible types for ((SDL_TRUE) == ((*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null))): 'int' and 'void'nullptr word. How I use this?Does it work if you just use `null` ?
May 03 2017
On Thursday, 4 May 2017 at 03:59:36 UTC, Leonardo wrote:On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote:Ahh, looks to be a bug in DerelictSDL2. null will work for that last parameter, the problem is that the function should be returning an SDL_bool, but in Derelict it's declared as returning void: that's what the error message is saying. I'll file a report, but with the conference underway, it may take a while to get fixed.On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:No. First I got: source/app.d(45,69): Error: expression (*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null) of type void does not have a boolean value then I change to: event.button.button == SDL_BUTTON_LEFT && SDL_TRUE == SDL_EnclosePoints(&mousePos, 1, &ball.bbox, null) and got: source/app.d(45,81): Error: void has no value source/app.d(45,52): Error: incompatible types for ((SDL_TRUE) == ((*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null))): 'int' and 'void'nullptr word. How I use this?Does it work if you just use `null` ?
May 03 2017
In the meantime, you can get around the issue by redeclaring the
function with another name and loading it manually just after
calling DerelictSDL2.load():
import derelict.sdl2.sdl;
__gshared SDL_bool function (const(SDL_Point)*, int,
const(SDL_Rect)*, SDL_Rect*) SDL_EnclosePoints_;
void main()
{
DerelictSDL2.load();
DerelictSDL2.bindFunc(cast(void**)&SDL_EnclosePoints_,
"SDL_EnclosePoints");
// ...
}
Now you'd need to call SDL_EnclosePoints_ instead of
SDL_EnclosePoints.
May 03 2017
On Thursday, 4 May 2017 at 04:34:40 UTC, Stanislav Blinov wrote:In the meantime, you can get around the issue by redeclaring the function with another name and loading it manually just after calling DerelictSDL2.load():Thank you.import derelict.sdl2.sdl; __gshared SDL_bool function (const(SDL_Point)*, int, const(SDL_Rect)*, SDL_Rect*) SDL_EnclosePoints_; void main() { DerelictSDL2.load(); DerelictSDL2.bindFunc(cast(void**)&SDL_EnclosePoints_, "SDL_EnclosePoints"); // ... }Now you'd need to call SDL_EnclosePoints_ instead of SDL_EnclosePoints.
May 16 2017









Stanislav Blinov <stanislav.blinov gmail.com> 