Mikrobasic 3.6.0 bug

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
serge87
Posts: 45
Joined: 12 Sep 2012 17:55

Mikrobasic 3.6.0 bug

#1 Post by serge87 » 06 Jan 2016 10:44

Hello,
I've found a bug in the mikrobasic compiler.
This is my test program:

Code: Select all

program test_symbol_bug
symbol connected = 10
symbol disconnected = 20
dim i as char


main:
uart2_init(115200)
i = connected
do
  if i = connected then
     uart2_write_text("connected" + chr(13) + chr(10))
     i = disconnected
  else
      uart2_write_text("disconnected" + chr(13) + chr(10))
      i = connected
  end if

delay_ms(2000)
loop until 1 = 0

end.
This is the result:
symbol bug.png
symbol bug.png (66.96 KiB) Viewed 5737 times
It seems that the compiler doesn't make the difference between an "symbol" and a string.
The output from the uC to the terminal should be "connected" and "disconnected" not the symbols declarated.

Thank you.
Just tell me....

rc.ozzy
Posts: 7
Joined: 03 Jan 2016 09:20

Re: Mikrobasic 3.6.0 bug

#2 Post by rc.ozzy » 12 Jan 2016 02:28

Really! you're right...
I conducted several tests, and only was correct when he removed the associations 'symbol'.
I use mikroBasic (not PRO) v7.2, PIC18F4550 and Proteus
Thanks for the info!
my program that worked ...

program test_symbol_bug
dim i as char
connected as char
disconnected as char

main:
USART_init(9600) 'init.USART module(8 bit,9600baud rate,no parity...)
connected = 10
disconnected = 20
i = connected
do
if i = connected then
USART_write_text("connected" + chr(13) + chr(10))
i = disconnected
else
USART_write_text("disconnected" + chr(13) + chr(10))
i = connected
end if

delay_ms(2000)
loop until 1 = 0

end. :mrgreen:

serge87
Posts: 45
Joined: 12 Sep 2012 17:55

Re: Mikrobasic 3.6.0 bug

#3 Post by serge87 » 13 Jan 2016 16:35

I know that will work, but consider my case:
I have about 50 (and that number will grow) symbols in my program for use in passing statuses between my functions.
If I am to use your method of dealing with this I will consume 50 bytes of RAM (if there were only byte sized variables, which there aren't) for storing constants, which with the "symbol" method the compiler will replace the "name" with the value at compile time requiring no ram at all.
The problem arise when the compiler doesn't make the difference between the name of said symbol and a string constant which contains the same text as the symbol name.

I'm still waiting for somebody from ME staff to dial in, in order to know that my problem reached the right audience.

Thank you.
Just tell me....

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: Mikrobasic 3.6.0 bug

#4 Post by uros.cvetinovic » 14 Jan 2016 17:01

Hi,

Symbols in basic is something like #define in c.
So it is normal to get 10 instead of connected, and 20 instead of disconnected.

Try like this:

Code: Select all

program test_symbol_bug
symbol connect = 10
symbol disconnect = 20
dim i as char


main:
uart2_init(115200)
Delay_ms(100)
i = connect
do
  if i = connect then
     uart2_write_text("connected" + chr(13) + chr(10))
     i = disconnect
  else
      uart2_write_text("disconnected" + chr(13) + chr(10))
      i = connect
  end if

delay_ms(2000)
loop until 1 = 0

end.
Best regards,

Uros Cvetinovic

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: Mikrobasic 3.6.0 bug

#5 Post by aCkO » 15 Jan 2016 11:19

uros.cvetinovic wrote:Symbols in basic is something like #define in c.
So it is normal to get 10 instead of connected, and 20 instead of disconnected.
No, it isn't. C preprocessor does not interfere with string literals. That simply doesn't make sense.

Example:

Code: Select all

#define connected   10

char txt[10];

strcpy(txt, "connected");   // txt is now "connected", not "10"
If you allow this kind of behavior you could easily find yourself in big trouble:

Code: Select all

symbol test = something_very_long

dim txt as string[5]

txt = "test"   ' memory corrupted !!!
This is a bug and it should be treated as such.

Regards

serge87
Posts: 45
Joined: 12 Sep 2012 17:55

Re: Mikrobasic 3.6.0 bug

#6 Post by serge87 » 03 Feb 2016 20:32

Thanks aCkO, that is my reasoning too, the "symbol" command mustn't interfere with the string constants or variables except when it is applied to them.

Regards.
Just tell me....

Post Reply

Return to “mikroBasic PRO for PIC32 General”