Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Problem with compiling example for inline C-code

 
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode
Author Message
kranenborg



Joined: 27 Jul 2009
Posts: 37
Location: Uppsala, Sweden

Posted: 06 October 2009, 22:59 PM    Post subject: Problem with compiling example for inline C-code Reply with quote

Hello,

As a preparation to using inline C-code on native mode devices I tried to compile the example program in Section 4.1 of the manual for a ZX328L:

Code:

Dim b as Byte

#c
char ch;
#endc

Sub Main()
b = 5

#c
ch = zv_b;
#endc
End Sub


With the verbose option set I get the following message:
avr-gcc -c -DF_CPU=14745600UL -Dzx328nu -mmcu=atmega328p -I"C:/Program Files/ZBasic/zxlib" -I. -gdwarf-2 -Os -Wall -funsigned-char -fpack-struct -Wstrict-prototypes -std=gnu99 -fgnu89-inline testdouble.c -o testdouble.o
testdouble.c: In function 'zf_Main':
testdouble.c:44: error: 'zv_b' undeclared (first use in this function)

It is not clear to me why running the exact example does not work, maybe someone can be of help here?

Best regards,
Jurjen
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2493
Location: Portland, OR

Posted: 07 October 2009, 2:36 AM    Post subject: Re: Problem with compiling example for inline C-code Reply with quote

kranenborg wrote:
It is not clear to me why running the exact example does not work, maybe someone can be of help here?
The example was correct at one time but is now out of date. The naming convention for private module-level variables was changed to avoid a possible conflict with a public module-level variable of the same name defined in another module (a perfectly legal but probably inadvisable arrangement).

Currently, private module-level variables have the prefix "mzv_" instead of just "zv_" as before. Consequently, the example should be changed thusly:
Code:
Dim b as Byte
#c
char ch;
#endc

Sub Main()
  b = 5
#c
  ch = mzv_b;
#endc
End Sub

Alternately, the example could read:
Code:
Public b as Byte
#c
char ch;
#endc

Sub Main()
  b = 5
#c
  ch = zv_b;
#endc
End Sub
Back to top
kranenborg



Joined: 27 Jul 2009
Posts: 37
Location: Uppsala, Sweden

Posted: 07 October 2009, 21:37 PM    Post subject: Reply with quote

Thanks Don, that worked out very well.

The simple example allows for some experimentation; moving the initialization of b inside the C-code required the use of the "Used" attribute in order to compile because b seems to be not used from the ZBASIC point of view (this took me a while, being focused on the volatile attribute instead). For what it is worth:

Code:


Public b as Byte Attribute(Used)

#c
char ch;
#endc

Sub Main()

#c
  zv_b = 5;
  ch = zv_b;
#endc

End Sub

Back to top
kranenborg



Joined: 27 Jul 2009
Posts: 37
Location: Uppsala, Sweden

Posted: 09 October 2009, 21:07 PM    Post subject: Reply with quote

Continuing further with C code inlining I found that the very commonly used include file "stdio.h" (quite empty in the AVR version but not completely void) gives problems (all other include files that come with the Zbasic installatiion appear to work well):

Code:


Option TargetCPU ZX328nu
Sub Main()

#c
#include <stdio.h>
#endc

End Sub



Compiling this one gives the following message:

Quote:


>"C:\Program Files\ZBasic\zbasic.exe" --target-device=ZX328nu --directory="C:\Documents and Settings\sejukra\Desktop\Jurjen\Electronics\projecten\ZBASIC/" --project="HelloWorld.pjt"
make: Entering directory `C:/Documents and Settings/sejukra/Desktop/Jurjen/Electronics/projecten/ZBASIC/zx_x3nfdM'
avr-gcc -c -DF_CPU=14745600UL -Dzx328nu -mmcu=atmega328p -I"C:/Program Files/ZBasic/zxlib" -I. -gdwarf-2 -Os -Wall -funsigned-char -fpack-struct -Wstrict-prototypes -std=gnu99 -fgnu89-inline test.c -o test.o
In file included from test.c:39:
c:/program files/zbasic/winavr/bin/../avr/include/stdio.h: In function 'zf_Main':
c:/program files/zbasic/winavr/bin/../avr/include/stdio.h:939: error: invalid storage class for function 'fflush'
make: *** [test.o] Error 1



I have also WinAvr installed, the corresponding version of stdio.h is identical with the Zbasic version but compiles without problems on that platform (which has a newer version of gcc). Does the Zbasic gcc version need to be upgraded?

/Jurjen
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2493
Location: Portland, OR

Posted: 09 October 2009, 21:49 PM    Post subject: Reply with quote

kranenborg wrote:
Continuing further with C code inlining I found that the very commonly used include file "stdio.h" [...] gives problems
There isn't anything in stdio.h that is useful in ZBasic code so there's not much point in including it. In any event, such includes should be done at the module level, i.e. outside of any procedures.
Code:
#c
#include <stdio.h>
#endc
Sub Main()
End Sub

If you look at the file zxlib.h (part of the ZBasic native mode files), you'll see that a number of common include files are already included in every application. On occasion, there may be others that you need for special purposes.

kranenborg wrote:
Does the Zbasic gcc version need to be upgraded?
No. Although future releases of ZBasic may use a newer version of the avr-gcc compiler, it is inadvisable to attempt to use a newer version than the one supplied, not least because it hasn't been tested and there may be compile-time, link-time or run-time issues.
Back to top
kranenborg



Joined: 27 Jul 2009
Posts: 37
Location: Uppsala, Sweden

Posted: 09 October 2009, 22:27 PM    Post subject: Reply with quote

Thanks Don, that explained all I needed. Diving into zxlib.h

/Jurjen
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group