passing strings byval into a subroutine - avr-gcc erroir

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
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

passing strings byval into a subroutine - avr-gcc erroir

Post by ndudman »

Hi

I don't get a avr-gcc compiler error if the sub takesastring is defined as byref, if its defined as below, i.e byval then i get the below errors... full at end of message.
  • undefined reference to `FIX_PARM_STR'
With the following code

Code: Select all

sub takesastring(byval str as string)

end sub

Sub Main()
	Dim str as string = "a string"
	call takesastring(str)
End Sub
I get the following error
  • >"C:\PROGRAM FILES\ZBASIC\zbasic.exe" --target-device=ZX24n --directory="C:/" --project="test7.pjt"
    make: Entering directory `C:/zxTempDir/test7'
    avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/PROGRAM FILES/ZBASIC/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct test7.c -o test7.o
    test7.c: In function 'zf_takesastring':
    test7.c:53: warning: implicit declaration of function 'FIX_PARM_STR'
    test7.c:55: warning: implicit declaration of function 'FREE_PARM_STR'
    test7.c:53: warning: 'strTypeSave1' is used uninitialized in this function
    avr-gcc -o test7.i1 -mmcu=atmega644p -L"C:/PROGRAM FILES/ZBASIC/zxlib" -Wl,-T,"C:/PROGRAM FILES/ZBASIC/zxlib/zx_avr5.lds" -u rtc_ISR -u default_ISR test7.o -lzx24n -lm
    test7.o: In function `zf_takesastring':
    C:\zxTempDir\test7/test7.c:53: undefined reference to `FIX_PARM_STR'
    C:\zxTempDir\test7/test7.c:55: undefined reference to `FREE_PARM_STR'
    make: *** [test7.i1] Error 1
    make: Leaving directory `C:/zxTempDir/test7'
    Error: one or more errors occurred in the back-end build process for "test7.zxb"
    >Exit code: 1
Thanks
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: passing strings byval into a subroutine - avr-gcc erroir

Post by dkinzer »

ndudman wrote:

Code: Select all

C:\zxTempDir\test7/test7.c:53: undefined reference to `FIX_PARM_STR'
C:\zxTempDir\test7/test7.c:55: undefined reference to `FREE_PARM_STR'
Both of those identifiers are defined in zxlib.h and I've confirmed that the v2.6.9 installer contains a version of that file that has the definitions. If you originally used an earlier installer (perhaps as late as v2.6.6) and you're now using the v2.6.10 compiler, that would explain the problem.

Perhaps the simplest way to correct this issue is to download the v2.6.4 ZX Library .zip file and extract the files in it to the zxlib directory of the ZBasic installation directory. You can find a link to that .zip file on the downloads page or using the link below.

http://www.zbasic.net/downloads.php#zxlib
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I just realized that the output in your original post indicates that a makefile is being used for the back end build. Which version of the compiler did you use to produce that result?
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

It was the latest NON experimental from download page of website 2.6.9... i installed only the compiler download

However I just got the same error when I compiled (passing strings as byval) using the experimental 2.6.9.10.

If it helps any when I use byref the FREE_PARM_STR etc arnt inserted into the c functions (end and begining) but when byval they are and hence the error. I confirm this with the latest 2.6.9.10

Neil
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Sorry I forgot to add that I also have in project file
--optimize=no-unreferenced-code
If I remove this then I dont get the problem, I was worried that the problematic function/subs that caused it were perhaps being optimized out (perhaps not) so I called one directly from Main() and did not get an error when the --optimize=no-unreferenced-code option was NOT used, but do get problem when it is used.

Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:It was the latest NON experimental from download page of website 2.6.9... i installed only the compiler download
I believe, then, that that means that you did the original ZBasic installation by using the v2.6.6 or earlier installer. I'm fairly certain that the zxlib.h file included with the older installers does not have the FREE_PARM_STR macro defined. You can confirm this by loading zxlib.h into any editor and searching for that string.

If it is missing, you can correct the problem by extracting the files from the v2.6.4 ZX Library to the zxlib subdirectory of the ZBasic installation directory.
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

As I remember correctly I installed zbasic a few weeks ago from the version of the zbasic installer just prior to the latest on the website which was 2.6.5

Just done what you suggested in last post... and it did the trick.

Thanks
Neil
Post Reply