|
Post by bitvast on Oct 13, 2014 11:51:28 GMT 1
I used a variable named "switch" in a program and got an error:
switch = 0
INCR switch In file included from baconshell.bac.c:2:0: baconshell.bac.h:4:6: error: expected identifier or '(' before 'switch' long switch; ^ baconshell.bac.c: In function 'main': baconshell.bac.c:62:7: error: expected '(' before '=' token switch=(long)0; ^ baconshell.bac.c:64:8: error: expected '(' before '=' token switch = switch + (1); ^ make: *** [baconshell.bac.o] Error 1
Then it occurred to me that it's because "switch" is a C keyword, so I tried using "register" and "auto" as variable names and got the same error. So I think that there should be a note in the manual mentioning this.
|
|
|
Post by vovchik on Oct 13, 2014 13:33:31 GMT 1
Dear bitvast,
Good thing you brought up that business. Somewhere, you might want to include them in a list. Peter once mentioned the following:
Libm has more, and I had problems with some variables until I realized that they were predefined.
More info on reserved var names is here:
https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
and here.
http://www.tutorialspoint.com/ansi_c/c_reserved_keywords.htm
With kind regards, vovchik
|
|
|
Post by bitvast on Oct 13, 2014 15:52:46 GMT 1
Hi vovchik, Yes I've come across the problem before too. Perhaps a list of these predefined variables could be included in an appendix in the manual. But maybe there are more depending on which C library you're using, in which case there could be no end to them!
|
|
|
Post by Pjot on Oct 13, 2014 20:06:21 GMT 1
Hi bitvast, Well, you're right of course, C keywords cannot be used as variable names - and though BaCon is a BASIC-to-C converter, still we may not always realize that C keywords cannot be used. Not long ago I ran into the same situation with the keyword 'volatile'. By default, any binary compiled by BaCon links with libc, libm and ldl. Any predefined names in these libraries cannot be used by BaCon code. I could add the most common ones, like the C keywords and libm variables like y0, y1 etc. into an appendix in the manual? Anyway, note that this whole situation is the very reason that BaCon statements must be written in capitals, just to avoid some accidental name clash with C keywords, C library functions names or predefined variable names used in external libraries, or macro's. @ vovchik: thanks for that link about reserved names, very useful! Thx for your suggestions Peter
|
|
|
Post by bitvast on Oct 14, 2014 17:29:41 GMT 1
I could add the most common ones, like the C keywords and libm variables like y0, y1 etc. into an appendix in the manual? Thanks Peter, sounds like a plan.
|
|
|
Post by bitvast on Oct 15, 2014 17:52:47 GMT 1
In the manual, the example in the "Strings by value or by reference" section doesn't work as expected:
a$ = "Hello world..." LOCAL b TYPE STRING b = a$ a$ = "Goodbye..." PRINT a$, b FORMAT "%s%s\n"
Should output
but it only outputs
|
|
|
Post by Pjot on Oct 15, 2014 19:27:33 GMT 1
Thanks for noticing bitvast,
Actually, this is a documentation bug. The sample code should look like this:
a$ = "Hello world..." LOCAL b TYPE STRING a$ = "Goodbye..." b = a$ PRINT a$, b FORMAT "%s%s\n"
I will change this in the manual.
Thx Peter
|
|
|
Post by bitvast on Nov 11, 2014 11:23:20 GMT 1
Peter,
Minor bug in the latest beta: You've renamed the Shell to Scratch Pad, but the tooltip still says "BaCon Shell".
|
|
|
Post by Pjot on Nov 11, 2014 20:52:44 GMT 1
Thanks for noticing! Changed.
BR Peter
|
|
|
Post by Pjot on Nov 25, 2014 10:03:37 GMT 1
All, Thanks for your input and findings. The last bugs and typos caused by the code overhaul in the 3.x series now should be solved. It is the intention to release 3.0.2 at December 1, 2014. The latest version can be found at the beta directory. So if you find any bugs or weird behavior in this last beta version, please let me know! Best regards Peter
|
|
|
Post by bitvast on Nov 27, 2014 23:02:54 GMT 1
Latest beta with the new lowercase keyword/function option crashes bacongui.
This was the code I used to test it:
declare x[5] type int print "Counting up..." for x[1] = 1 to 10 print x[1], " - "; next print "Counting down..." for y = 10 to 1 step -1 print y next y
It converts and compiles ok, but after responding to the "execute" message, bacongui crashes (it doesn't matter whether you choose "yes" or "no" to execute).
The program executes ok if it has been previously built with the lowercase option checked. i.e. after the crash, restarting bacongui, loading the program and then clicking "execute" was ok.
P.S. This is a really nice addition. I wonder how many would prefer having lowercase as the default?
|
|
|
Post by Pjot on Nov 27, 2014 23:15:10 GMT 1
Hi bitvast, Well, just tested this program but it works fine for me? No crash whatsoever, also a check with valgrind does not show any memory problems (see below). Can you run the resulting binary with 'valgrind' and show the output? Note that in BaconGUI, you *must* enable "allow lowercase keywords" prior to compilation. I did it like this to be backwards compatible. A lot of programs cannot be compiled in lowercase, because they use variable names which also occur as a keyword (like 'option' or 'exit'). With the console baCon use the '-z' switch. Anyway, if you want to lowercase (or uppercase) your programs, I prepared some M4 macros which can help you out with this. BR Peter
|
|
|
Post by bitvast on Nov 28, 2014 9:58:09 GMT 1
Hi Peter, It's bacongui which is crashing, the binary of the test program runs fine. I tried using the command line bacon with -z and there was no problem. I ran bacongui with valgrind and saved the output to a file (attached) although not sure how useful it will be. Here is the output in the terminal right up to when bacongui crashed: jules[~]$ valgrind --log-file="results.txt" bacongui java version "1.7.0_51" OpenJDK Runtime Environment (IcedTea 2.4.5) (Slackware) OpenJDK Server VM (build 24.51-b03, mixed mode) GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. ** Gtk:ERROR:gtkfilesystemmodel.c:746:gtk_file_system_model_sort: assertion failed: (r == n_visible_rows) Killed As I mentioned in my previous post, conversion is ok. So I click "Start Conversion", then select "Allow lowercase keywords", and "Convert". It's only after the conversion and I get the message asking me to execute the binary that bacongui crashes (after I've selected yes or no). Attachments:results.txt (18.98 KB)
|
|
|
Post by Pjot on Nov 28, 2014 10:52:11 GMT 1
Thanks bitvast,
Unfortunately your Valgrind logging cannot help us because of two reasons:
(1) the 'bacongui' binary is compiled with the '-O2' compiler flag, this confuses the memory checking of Valgrind - it will show 'invalid memory' a lot of times becaise of the compiler optimization. (2) the 'bacongui' binary also needs the '-g' compiler flag to show actual source code lines.
Recompiling on my 64bit Linux Mint 17 XFCE edition, the valgrind output does not show anything special (apart from the usual GTK memory leaks).
If you can recompile the bacongui source code (first comment line 35 'PRAGMA OPTIONS -O2') and add the '-g' compiler flag:
Please run the same session through Valgrind again, then the logging should give some indication.
Thx Peter
|
|
|
Post by bitvast on Nov 28, 2014 11:56:16 GMT 1
Hi Peter,
I commented out line 35 in bacongui.bac in the beta folder (PRAGMA OPTIONS -O2) and recompiled using:
# bacon -o -g bacongui.bac # valgrind ./bacongui
But the resulting log file doesn't have any more info than previously. In particular, there are no source code lines shown. Are you sure I don't need to add some other switches?
By the way, I'm using the gtk-2 version of bacongui.
|
|