C/PB Variable Types

Just starting out? Need help? Post your questions and find answers here.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

C/PB Variable Types

Post by Inner »

I have some C types that I'm unable to find conclusive data on probably the confusion is some search results are 64bit and 32bit, if someone could fill the holes I'd be greatful.

it's obviously a sqlite table, that's intended to reference purebasic veriables.

(type, bytesize,minrange, maxrange, pbisequal)

Code: Select all

"('char',              '1 Byte', '-128','+127',              'Byte')")
"('unsigned char',     '1 Byte', '0',   '255',               'Ascii')")    
"('int',               '2 Byte', '-2147483648','+2147483647','Long')")
"('unsigned int',      '2 Byte', '0','+4294967295',          '')")    
"('short int',         '1 Byte', '-32768','+32767',          'Word')")
"('unsigned short int','?',      '0','+65535',               'Unicode')")    
"('long',              '',       '','',                      '')")
"('unsigned long',     '',       '','',                      '')")    
"('long int',          '4 Byte', '','',                      '')")
"('unsigned long int', '4 Byte', '','',                      '')")    
"('float',             '4 Byte', '','',                      'Float')")
"('double',            '8 Byte', '','',                      'Double')")
"('long double',       '10 Byte','','',                      '')")
User avatar
idle
Always Here
Always Here
Posts: 6044
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C/PB Variable Types

Post by idle »

don't know what long double offhand most likely 16 bytes for SSE
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: C/PB Variable Types

Post by juergenkulow »

C data types are not unique and depend on implentation.
programiz c-data-types
Wiki Integer Common_integral_data_types
Wiki C_data_types
Axolotl
Addict
Addict
Posts: 873
Joined: Wed Dec 31, 2008 3:36 pm

Re: C/PB Variable Types

Post by Axolotl »

Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C/PB Variable Types

Post by mk-soft »

If you can't find a type size again, check with c.

Update

Code: Select all

; Check size with c-backend

Global size

; Window: long x86 = 4 bytes, x64 = 4 bytes
; Linux, macOS: long x86 = 4 bytes, x64 = 8 bytes

! long value;
! g_size = sizeof(value);
Debug size

; x86 = 4 bytes, x64 = 8 bytes
! int iValue;
! g_size = sizeof(iValue);
Debug size

Debug SizeOf(Integer)
Last edited by mk-soft on Sat Dec 09, 2023 1:59 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Axolotl
Addict
Addict
Posts: 873
Joined: Wed Dec 31, 2008 3:36 pm

Re: C/PB Variable Types

Post by Axolotl »

Hi mk-soft,
I tried your code and did not get the result i expected: :oops:

Code: Select all

; Check size with c-backend

Global size

; x86 = 4 bytes, x64 = 8 bytes
! long value;
! g_size = sizeof(value);
Debug size	; == 4 -> not correct on x64 ?

; x86 = 4 bytes, x64 = 8 bytes
! int iValue;
! g_size = sizeof(iValue);
Debug size		; == 4 -> not correct on x64  

Debug SizeOf(Integer) 	; == 8	
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C/PB Variable Types

Post by mk-soft »

A 'c' int is always 32 bit

An integer is defined for PB:
X86

Code: Select all

typedef long long quad;
typedef int integer;
X64

Code: Select all

typedef long long quad;
typedef quad integer;
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C/PB Variable Types

Post by mk-soft »

Just tested.

Once again typical OS.

X64 Window:
c type long = 4 byte

X64 Linux, macOS
c type long = 8 byte

Therefore, the pb type Quad is always defined as long long so that it also has 8 bytes on all OSs
and pb type long is defined as c type int (32bit)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C/PB Variable Types

Post by mk-soft »

We have to start from GCC compiler and not from other c compilers
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 2068
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: C/PB Variable Types

Post by Shardik »

Here you find a nice overview table for C data types in the German Wikipedia (at the end of the article).
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: C/PB Variable Types

Post by Inner »

Thanks all very informative.. however I didn't intend to start are type war :oops: lol
User avatar
idle
Always Here
Always Here
Posts: 6044
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C/PB Variable Types

Post by idle »

I really shouldn't answer questions when I'm tired and suffering brain fog.
Post Reply