Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with C function in compiled qb exe
#1
Hello,

I wrote small routine in C(borland Turbo C/C++ 3.1). Made an .OBJ file from it and linked with VBDCL10E.LIB into funk.lib file, from what I made a .qlb file.

C function: (compiled using medium model(386 code generation)
Code:
int far ontarget(int mx, int my, int xpos, int ypos, int x1pos, int y1pos)
{
    if (mx < xpos) return 0;
    if (mx > x1pos) return 0;
    if (my < ypos) return 0;
    if (my > y1pos) return 0;
    return -1;
}

In qb everything works just fine. Made even small test program to see wich is faster. Just in case here's qbasic code:
Code:
DEFINT A-Z
DECLARE FUNCTION ontarget CDECL (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
DECLARE FUNCTION OnTarget2 (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
CLS
PRINT "C function"
PRINT ontarget(100, 100, 50, 50, 150, 150)
PRINT ontarget(100, 10, 50, 50, 150, 150)

StartTest1! = TIMER
   FOR i = 1 TO 32000
      FOR m = 1 TO 1000
         a = ontarget(100, 100, 50, 50, 150, 150)
      NEXT m
   NEXT
EndTest1! = TIMER
PRINT EndTest1! - StartTest1!

PRINT "qb function"
PRINT ontarget(100, 100, 50, 50, 150, 150)
PRINT ontarget(100, 10, 50, 50, 150, 150)

StartTest1! = TIMER
   FOR i = 1 TO 32000
      FOR m = 1 TO 1000
         a = OnTarget2(100, 100, 50, 50, 150, 150)
      NEXT m
   NEXT
EndTest1! = TIMER
PRINT EndTest1! - StartTest1!

FUNCTION OnTarget2 (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
IF mx < Xpos THEN EXIT FUNCTION
IF my < Ypos THEN EXIT FUNCTION
IF mx > X1pos THEN EXIT FUNCTION
IF my > Y1pos THEN EXIT FUNCTION
OnTarget2 = -1
END FUNCTION
(C function completes test with smth of 12.xxx seconds and qb's function takes 20.xxx seconds :wink: )

Now the problem is when I compile it into exe. (using /g3 switch(it's VBDOS))

It compiles without errors. Everything is fine. But when I ran the test, it seems that C function doesn't return any value. It just returns 0 whenever function is called. Dunno why is it so. Did I compile smth wrong?
url]http://fbide.sourceforge.net/[/url]
Reply
#2
I might be wrong, but aren't return values passed in the ax register as opposed to being passed on the stack? And I think the return command in C returns the value on the stack.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#3
You have to declare the routine as cdecl expliciltly, otherwise borland will use its own calling convention.
oship me and i will give you lots of guurrls and beeea
Reply
#4
Hey Von Godric, what is the runtime libe VBdDOS use to make QLB's?
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
VBDOSQLB.LIB
Reply
#6
VBDCL10E.LIB
url]http://fbide.sourceforge.net/[/url]
Reply
#7
lol... They have different versions?

Sorry about that rel.
Reply
#8
Dude, did you try what i said?
oship me and i will give you lots of guurrls and beeea
Reply
#9
Sry ... not yet. I had some problems with win98... Dunno I guess installer was corrapted or smth... well anyway I'll try and let you know.
Tnx
url]http://fbide.sourceforge.net/[/url]
Reply
#10
nope Cry

I put:
Code:
int far pascal ontarget(...)
and had to remove cdecl statament in qb code. Again works fine in qb ide, but doesn't as soon as I compile the program and try to run it.
url]http://fbide.sourceforge.net/[/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)