LONGINT causing problems

General FreeBASIC programming questions.
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

LONGINT causing problems

Post by skystrick »

Switched some variables in a program from INTEGER to __LONGINT (I am using -lang qb), now FBC compiler throws this error:

PROGRAM.o: In function 'main':
PROGRAM.c:(.text+0x2bdf3): undefined reference to '__moddi3'
PROGRAM.c:(.text+0x2be9e): undefined reference to '__moddi3'

Help?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: LONGINT causing problems

Post by MrSwiss »

Well, AFAIR, in: lang "QB" a Integer = Short (in lang "FB", aka: 16bit 'integer-type').
A LongInt (64bit) is therefore, 4 x SizeOf(Short), I'd try to use __Long instead (32bit).

I've never used -lang "QB", and never will (for obvious reasons).
The best bet, IMHO is, to switch to: -lang "FB" ...

Questions: which OS (32/64) ? which FBC (32/64bit) ?
Last edited by MrSwiss on Oct 17, 2017 18:02, edited 1 time in total.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: LONGINT causing problems

Post by dkl »

Hi, it looks like a bug with the -lang qb code generation on 64bit. I'm going to make a bug report.
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: LONGINT causing problems

Post by xlucas »

Skystrick: I'm not being able to reproduce your error. I create a simple program using -lang qb and one Integer variable and it compiles and runs fine. I change the variable to __LongInt and it still runs perfectly. Can you post the code?

Also, MrSwiss is right. The QB dialect is there so that you can compile old QB programs with FB with little to no changes. If you're actually making changes to it, then you should seriously consider porting it to FB's native dialect unless it's just a minor touch you want to make. If you're building a new program, then you definitely should not use QB dialect. Of course, this does not respond to your initial question, so if you post your code, we can hopefully help more.

EDIT: Maybe it has to do with the platform? I'm compiling under GNU/Linux 32bit.
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Re: LONGINT causing problems

Post by skystrick »

dkl wrote:Hi, it looks like a bug with the -lang qb code generation on 64bit. I'm going to make a bug report.
Thanks! Any suggestions for a workaround? Or just wait for a patch?

xlucas wrote:EDIT: Maybe it has to do with the platform? I'm compiling under GNU/Linux 32bit.
I'm compiling under Ubuntu Linux 64-bit using FBC 1.05.0 (linux-x86_64)

This is a 64-bit bug so you were unable to reproduce it under 32-bit linux.

MrSwiss wrote:I've never used -lang "QB", and never will (for obvious reasons).
The best bet, IMHO is, to switch to: -lang "FB" ...
My programs require QB syntax, not looking to debate that point in this or any of my other threads. Thank you.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: LONGINT causing problems

Post by srvaldez »

hello skystrick
this code compiles and runs ok using FreeBASIC Compiler - Version 1.06.0 (02-04-2017), built for linux-x86_64 (64bit)

Code: Select all

#lang "qb"
dim as __LONGINT x
input "enter x ";x
print sqr(x)

print "enter return to exit "
sleep
my suggestion, try the latest fb build from http://users.freebasic-portal.de/stw/builds/ or get the git repo from https://github.com/freebasic/fbc and make and install.
if my example above does not throw the expected error then please post code that does not compile.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: LONGINT causing problems

Post by MrSwiss »

skystrick wrote:My programs require QB syntax
Seldom, on this forum, I've had to read such NONSENSE (you, might require), but not the compiler/program e.t.c.!

As you wish, you'll be IGNORED in future (rather, your posts here), just made it to the 'list', congratulations!
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: LONGINT causing problems

Post by fxm »

skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Re: LONGINT causing problems

Post by skystrick »

srvaldez wrote:hello skystrick
this code compiles and runs ok using FreeBASIC Compiler - Version 1.06.0 (02-04-2017), built for linux-x86_64 (64bit)

Code: Select all

#lang "qb"
dim as __LONGINT x
input "enter x ";x
print sqr(x)

print "enter return to exit "
sleep
Your code does compile and run without error on my system.

Something's going wrong with my code, but only when I use __LONGINT instead of INTEGER.

How can I decode the error locations (".text+0x2bdf3" and ".text+0x2be9e") to find what's going wrong in the .c file created by the compiler?

My code's over 20,000 lines long or I'd post it.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: LONGINT causing problems

Post by srvaldez »

thanks fxm, yes indeed there's a problem.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: LONGINT causing problems

Post by srvaldez »

if your code uses mod or division (have not tried the other operators) then there'a problem.
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Re: LONGINT causing problems

Post by skystrick »

srvaldez wrote:if your code uses mod or division (have not tried the other operators) then there'a problem.

Nailed it!

I used MOD twice :)

Wait for a bugfix or is there a workaround for MOD in 64-bit lang QB?
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: LONGINT causing problems

Post by srvaldez »

may I suggest that you use QB64 instead of FB http://www.qb64.net or https://www.qb64.org forum http://www.qb64.net/forum/index.php
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Re: LONGINT causing problems

Post by skystrick »

srvaldez wrote:may I suggest that you use QB64 instead of FB http://www.qb64.net or https://www.qb64.org forum http://www.qb64.net/forum/index.php
I depend on several commands/features supported only by FreeBASIC (even in -lang qb). 20,000+ lines of code in my program would be a lot to rewrite.

Without MOD, I need another way to determine whether Number X is evenly divisible by Number Y.

Currently I test whether X MOD Y = 0 is true (if it is, there is no remainder for X DIV Y, thus it is evenly divisible).

What is another way to do this without using MOD or DIV?
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Re: LONGINT causing problems

Post by skystrick »

skystrick wrote:Without MOD, I need another way to determine whether Number X is evenly divisible by Number Y.

Currently I test whether X MOD Y = 0 is true (if it is, there is no remainder for X DIV Y, thus it is evenly divisible).

What is another way to do this without using MOD or DIV?
I think I solved my own problem:

Code: Select all

A = 1
DO
   IF Y * A = X THEN REMAINDER = "NO": EXIT DO
   IF Y * A > X THEN REMAINDER = "YES": EXIT DO
   A = A + 1
LOOP
This will determine, the same as " X MOD Y " whether X divided by Y produces a remainder (MODulus).

It starts at the lowest multiple of Y (1*Y) and increments up the multiples of Y (2*Y, 3*Y, 4*Y, etc.) until ether it hits a multiple which is equal to X (exits with remainder variable set to "NO"), or until it reaches a multiple which exceeds the value of X (exits with remainder variable set to "YES", because no multiple of Y will equal X).

Anyone spot a problem?
Post Reply