• Print

Author Topic: C for QB64 - v.01  (Read 1631 times)

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
C for QB64 - v.01
« on: February 05, 2011, 04:49:18 PM »
Firstly, Clippy, in the wiki, under available c, the available c functions listed had an error.

Code: [Select]
SUB memset (pointer, value AS INTEGER, size_t num) 'Fills a block of memory. Sets the first

This code will not run in qb64.

Secondly, here is what i have done so far in accessing standard C library functions. Please can you merge the ones not listed in the wiki.

Code: [Select]
'http://QB64++ v.01 By John Onyon a.k.a Unseen Machine


DECLARE LIBRARY

'http:// ctime.h
  FUNCTION clock ()
  FUNCTION difftime# (BYVAL time2~&, BYVAL time1~&)

  'http://ctype.h
  FUNCTION isalnum (BYVAL c%)
  FUNCTION isalpha (BYVAL c%)
  FUNCTION isdigit (BYVAL c%)
  FUNCTION isgraph (BYVAL c%)
  FUNCTION islower (BYVAL c%)
  FUNCTION isprint (BYVAL c%)
  FUNCTION ispunct (BYVAL c%)
  FUNCTION isspace (BYVAL c%)
  FUNCTION isupper (BYVAL c%)
  FUNCTION isxdigit (BYVAL c%)
  FUNCTION tolower (BYVAL c%)
  FUNCTION toupper (BYVAL c%)

  'http:// math.h
  FUNCTION atan2# (BYVAL y#, BYVAL x#)
  FUNCTION acos# (BYVAL x#)
  FUNCTION asin# (BYVAL x#)
  FUNCTION cosh# (BYVAL x#)
  FUNCTION sinh# (BYVAL x#)
  FUNCTION tanh# (BYVAL x#)
  FUNCTION pow# (BYVAL base#, BYVAL exponent#)

  'http:// string.h
  FUNCTION strcspn% (str1$, str2$)
  FUNCTION strcmp% (str1$, str2$)
  FUNCTION strncmp% (str1$, str2$, BYVAL num%)
  SUB strncpy (dest AS STRING, source AS STRING, BYVAL Bytes AS INTEGER)

  'http:// stdio.h
  FUNCTION remove% (filename$)
  FUNCTION rename% (oldname$, newname$)

  'http:// stdlib.h
  FUNCTION atol& (str$)
  FUNCTION atoi% (str$)
  FUNCTION atof# (str$)
  SUB srand (BYVAL seed~&)
  FUNCTION rand& ()

END DECLARE
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: C for QB64 - v.01
« Reply #1 on: February 05, 2011, 05:45:57 PM »
I haven't tried it. What SHOULD it be? Or should it be removed?

I can when I get time.

QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: C for QB64 - v.01
« Reply #2 on: February 05, 2011, 06:24:07 PM »
I dunno what it should be, just QB reports an error on it. I dont remember doing that one, i'll look at it tomorrow.

John
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: C for QB64 - v.01
« Reply #3 on: February 05, 2011, 06:30:24 PM »
I found those, but I didn't check them. That's YOUR job...  ;)
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

chronokitsune

  • Guest
Re: C for QB64 - v.01
« Reply #4 on: February 05, 2011, 08:14:22 PM »
C declaration:
Code: [Select]
void * memset (void * ptr, int value, size_t num);

Closest equivalent QB64 declaration that I can manage, minus the return value since QB64 doesn't have pointers and `pointer' is already a parameter (remember that the INTEGER type in QB64 is 16-bit whereas the int type in C on x86, x86_64 and IA-64 machines is 32-bit):
Code: [Select]
SUB memset (pointer, value AS LONG, num AS _SIZE)
Note that _SIZE is just an example name for a corresponding type to size_t in C.  In other words, on x86_64 and IA-64 machines it would be 64-bit (_INTEGER64) and on x86 machines it would be 32-bit (LONG).  Sure, you could make it 64-bit across the board, but that could result in code breakage or even segfaults if the program managed to compile.  An alternative is to force QB64 compile to 32-bit only on all platforms via the -m32 switch and use LONG.  That way things like memset is properly handled on both 32-bit and 64-bit platforms.

codeguy

  • Hero Member
  • *****
  • Posts: 3555
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: C for QB64 - v.01
« Reply #5 on: February 07, 2011, 11:18:06 PM »
memory management always seems to be a big issue no matter how much we have.
and for those who don't have access to c's math library, i introduce a simplified version of CGatan2:
FUNCTION CGATan2# (ATan2x#, ATan2y#)
CGATan2# = 2 * ATN((ATan2y# / (SQR(ATan2x# * ATan2x# + ATan2y# * ATan2y#) + ATan2x#)))
END FUNCTION
i have benchmarked this already and it is approximately 30% slower than the c function, but if ya ABSOLUTELY need this, here it is. atan2 for (aTan2x#=0, ATan2y#=0) is technically undefined.
« Last Edit: February 08, 2011, 12:45:25 AM by codeguy »
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

  • Print