Liberty BASIC Community Forum
« Boolean data-type is obsolete for 32-bit API »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:09pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 sticky  Author  Topic: Boolean data-type is obsolete for 32-bit API  (Read 533 times)
Stefan Pendl
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Computers are like babies, you must teach them what you like them to do ...


Homepage PM

Gender: Male
Posts: 5303
xx Boolean data-type is obsolete for 32-bit API
« Thread started on: Dec 11th, 2011, 09:58am »

Many API newbies are translating the BOOL data-type in C to boolean in LB, which is not correct.

BOOL is 32-bit, where boolean is only 16-bit.

The correct translation for BOOL is long.
If one doesn't follow this he is likely to get a general protection violation error, which in turn is usually an overflow error, since the API function tries to return more then the data-type can handle.

Below find a small example showing the length of each of the LB API data-types.

Code:
    struct testc, c as char[1]
    struct tests, s as short
    struct testb, b as boolean
    struct testw, w as word
    struct testl, l as long
    struct testp, p$ as ptr
    struct testst, tests as struct
    struct testd, d as double

    print "Length of data types in bytes, for bits multiply by 8"
    print
    print "char[1] .... "; len(testc.struct)
    print "(u)short ... "; len(tests.struct)
    print "boolean .... "; len(testb.struct)
    print "word ....... "; len(testw.struct)
    print "(u)long .... "; len(testl.struct)
    print "pointer .... "; len(testp.struct)
    print "struct ..... "; len(testst.struct)
    print "double ..... "; len(testd.struct)
    print
    print "finished ..."
    end
 


For best translation results always follow the advice at Converting C types to LB types.

Happy API coding ;D
User IP Logged

Stefan

Make sure to read and follow the Forum Guidelines

Liberty BASIC Pro 4.04, Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
snoopy11
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 108
xx Re: Boolean data-type is obsolete for 32-bit API
« Reply #1 on: Dec 22nd, 2011, 12:44pm »

Thanks for this Stefan...

I know you have told me this before

but it hasn't sunk in.... yet.

anyway thanks for the heads up.

Snoopy.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls