[SOLVED] Suspicious Pointer Assignment

General FreeBASIC programming questions.
Post Reply
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

[SOLVED] Suspicious Pointer Assignment

Post by Munair »

Is there a way similar to FreePascal to suppress compiler warnings inline? I got this annoying "suspicious pointer assignment" warning, even though the pointer type is correct. It involves a gtk procedure call and according to the bindings it should be correct. The handle_ pointer can be of two types, either GtkWidget ptr or GtkStackSwitch ptr. Either way I get the warning:

Code: Select all

function TStackSwitcher.GetStack() as GtkWidget ptr
	return gtk_stack_switcher_get_stack(GTK_STACK_SWITCHER(handle_)) ' SUSPICIOUS POINTER ASSIGNMENT
end function

sub TStackSwitcher.SetStack(byref widget as GtkWidget ptr)
	gtk_stack_switcher_set_stack(GTK_STACK_SWITCHER(handle_), GTK_STACK(widget)) ' NO WARNING
end sub
Note that the warning only occurs with the get_stack procedure, not with the set_stack procedure. Going over the GTK3 bindings, I cannot find a difference.
Last edited by Munair on Nov 17, 2018 13:47, edited 1 time in total.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Suppress compiler warnings inline

Post by jj2007 »

You are opening a can of worms...

Code: Select all

.bas(25) warning 4(1): Suspicious pointer assignment
.bas(31) warning 1(1): Passing scalar as pointer, at parameter 1 of SETTEXTCOLOR()
.bas(32) warning 1(1): Passing scalar as pointer, at parameter 1 of SETBKMODE()
.bas(34) warning 5(0): Implicit conversion
.bas(49) warning 4(1): Suspicious pointer assignment
.bas(50) warning 2(1): Passing pointer to scalar, at parameter 3 of SETWINDOWLONGPTR()
.bas(50) warning 4(1): Suspicious pointer assignment
For a tiny 50 lines source that builds and runs fine in 32- and 64-bit mode. See also Free Basic Compilers Version 1.06.0 (08-26-2018) seem broken.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Suppress compiler warnings inline

Post by Munair »

Hmm. So far FB has not let me down and has been very consistent with pointer warnings and errors. While I was focused on the parameter passed, it later occurred to me that it could also be the return type. So far I have not had any problems with returning the base type which is GtkWidget ptr. In this particular case I tried to explicitly convert the return type and now the warning is gone:

Code: Select all

function TStackSwitcher.GetStack() as GtkWidget ptr
	return GTK_WIDGET(gtk_stack_switcher_get_stack(GTK_STACK_SWITCHER(Handle)))
end function
Alternatively I could change the return type to GtkStack ptr but the handle of the Stack object is of type Widget ptr so I will go for the explicit return type.
Post Reply