five in one: private declaration, byref and other problems

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
wwwoholic
Posts: 53
Joined: 23 December 2010, 20:58 PM

five in one: private declaration, byref and other problems

Post by wwwoholic »

This simple test gives me all kinds of errors. I did not include main as it simply calls dotest() from Module 2.
- Cannot use private enum as return type of private function
- Private structure definition is not exported into C code
- byref structure member produces several warnings and errors

module 1

Code: Select all

public robject as Reader
public class Reader
	public function read() as byte
		read = GetPin(C.0)
	end function
end class
module 2

Code: Select all

' error: a Public variable cannot have a type that is a Private enumeration
private enum Position
	Up
	Down
end enum

' error: unknown type name 'mzs_Info'
' note: expected 'struct zc_Reader *' but argument is of type 'struct zc_Reader **'
private structure Info
	dim r as Reader byref
end structure

' error: called object 'zf_6Reader_read((struct zc_Reader *)&mzv_sobject.zm_r)' is not a function
private function test(byref i as Info) as Position
	test = CType(sobject.r.read(), Position)
end function

' warning: passing argument 1 of 'zc_6Reader__Create' from incompatible pointer type [enabled by default]
private sobject as Info

public sub dotest()
	sobject.r.DataAddress = robject.DataAddress
	Debug.print CStr(test(sobject))
end sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

The issues have been analyzed and potential solutions identified. A new version of the compiler will be posted after the testing has been completed.
- Don Kinzer
wwwoholic
Posts: 53
Joined: 23 December 2010, 20:58 PM

Post by wwwoholic »

Hi Don,
I run the test above and the one from e-mail through 4.3.4 compiler, no errors. Awesome job, thanks! Now I have more for you to tackle:
"Error: the invocation of function "CheckRange" does not match any available candidates"
Commenting out CheckRange(integer) removes error. Interesting that moving code into one file with Main() also removes problem.

Code: Select all

option TargetDevice ZX24s
option Objects
public sub Main()
	call CheckSensors()
end sub

Code: Select all

public SLift as Sensor

public class Sensor
end class

public sub CheckRange(byval p as integer)
end sub

public sub CheckRange(byref s as Sensor)
end sub

public sub CheckSensors()
	call CheckRange(SLift)
end sub
wwwoholic
Posts: 53
Joined: 23 December 2010, 20:58 PM

Post by wwwoholic »

Looks like I spoke prematurely about the first test on this thread. While new compiler does not report any errors, the program does not work either.
When it comes to initializing byref field of the structure the controller resets, so the program goes into permanent reboot loop.

Yet another problem that I found during live test is that private variables are not initialized properly. To test add this to module 2:

Code: Select all

private pos as Position = Down
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

wwwoholic wrote:When it comes to initializing byref field of the structure the controller resets, so the program goes into permanent reboot loop.
The test case seems to execute properly. Do you have one that exhibits the problem that you mention.

As an aside, it is important to note that the ByRef field is initialized to zero when an instance of an Info structure is created. Invoking the test() function before setting the r member to a valid address will probably cause a reboot.
- Don Kinzer
wwwoholic
Posts: 53
Joined: 23 December 2010, 20:58 PM

Post by wwwoholic »

I think it was my fault with byref. The code I have is: sobject.r = robject
while I should have used sobject.r.DataAddress = robject.DataAddress
One should not write programs in 3 languages at the same time...
Post Reply