Difference between .a, .c and .b

Just starting out? Need help? Post your questions and find answers here.
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

Difference between .a, .c and .b

Post by nospam »

In this thread: http://www.purebasic.fr/english/viewtop ... 2&p=319687, a poster says:
.c is a dynamic type, thus .a and .u were introduced as non dynamic versions.
In addition, Fred says here: http://www.purebasic.fr/english/viewtopic.php?t=24952
Added: Character support (.c) for ascii (not for unicode)
And freak says here: http://www.purebasic.fr/english/viewtop ... 524#295524
Added: '.a' (ascii) and '.u' (unicode) native type to provide native unsigned byte and word.
So, from that I gather that .a defines an unsigned byte type, which would distinguish it from .b, which is a signed byte type.

Is that correct? If not, what is the real story?

I understand that the .c type changes to 2 bytes if the unicode compiler option is set on, however I don't understand how .c differs from .a when unicode is off. Can anyone shed light on this mystery for me please? Also, is it correct to say, as the poster above did, that ".c is a dynamic type, thus .a [is] non dynamic?" And if it is correct, what does it really mean?

Thanks for reading.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Difference between .a, .c and .b

Post by skywalk »

Here's my cheat sheet :wink:

Code: Select all

Structure ScanPBDataTypes
  ; These take up no memory and are allowed to grow without redim
  ; when the structure is pointed at a memory buffer.
  ; ex. *buf\d[i] ; 'i' being incremented in a loop
  ; Essentially, this is 1 big StructureUnion.
  ;         ; Type,      .?, Bytes, Min,                      Max
  b.b[0]    ; Byte,      b,  1,     -128,                     127
  a.a[0]    ; Ascii,     a,  1,      0,                       255
  c.c[0]    ; Character, c,  1,      0,                       255                 (ascii)
  ;c.c[0]   ; Character, c,  2,      0,                       65535               (unicode)
  u.u[0]    ; Unicode,   u,  2,      0,                       65535
  w.w[0]    ; Word,      w,  2,     -32768,                   32767
  l.l[0]    ; Long,      l,  4,     -2147483648,              2147483647
  i.i[0]    ; Integer,   i,  4,     -2147483648,              2147483647          (32-bit)
  ;i.i[0]   ; Integer,   i,  8,     -9223372036854775808,     9223372036854775807 (64-bit)
  q.q[0]    ; Quad,      q,  8,     -9223372036854775808,     9223372036854775807
  f.f[0]    ; Float,     f,  4,               -1.175494e-38,            3.402823e+38
  d.d[0]    ; Double,    d,  8,     -2.2250738585072013e-308, 1.7976931348623157e+308
  s.s{1}[0] ; String,    s,  {FixedLen} = Len, String$ = Len + 1 for chr(0)
  ;s.s[0]   ; FAILS, -> *p\s = @x$, *p\s[1] = IMA.
EndStructure
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

Re: Difference between .a, .c and .b

Post by nospam »

skywalk wrote:Here's my cheat sheet :wink:
Thanks, but that's pretty much what's in the help text. Unfortunately it doesn't help me understand the difference between .a and .c, or what I quoted above actually means. Unless I'm missing something.
; These take up no memory and are allowed to grow without redim
; when the structure is pointed at a memory buffer.
; ex. *buf\d ; 'i' being incremented in a loop

That's helpful, though without a bit of code wrapped around it I'm not fully understanding how *buf\d is defined. I think I'm in dense mode today.

Thanks for taking the time to reply.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Difference between .a, .c and .b

Post by infratec »

Hi nospam,

.a and .c are the same if you compile your program not in unicode mode,
and they are different in unicode mode.

So:

Use .c when you want to store single characters from a string.
Than you are save in both modes.

Use .a if you have to store an unsigned byte.

Bernd
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Difference between .a, .c and .b

Post by Demivec »

The .c type changes depending on the compile mode.

.c is the same as .a when the compile mode is ASCII.
.c is the same as .u when the compile mode is Unicode.


Because .c changes it's size depending on the compile mode (making it dynamic) you can use the types .a and .u to represent characters of a specific size (making it non-dynamic or static). This makes it possible for an ASCII program to handle individual unicode characters easier and for a Unicode program to handle individual ASCII characters. The .a and .u types are available as a convenience and for completeness when dealing with character types. The unsigned data types are also useful for other things that have no relation to character values.

The types .c, .a, and .u mimic the similar relationship between the types .i, .l, and .q. This is because the .i type changes size depending on whether 32-bit or 64-bit code is being compiled for and becomes equivalent to either .l or .q as a result.
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

Re: Difference between .a, .c and .b

Post by nospam »

Demivec wrote:Because .c changes it's size depending on the compile mode (making it dynamic)
Ah! :idea: :idea: :idea: Thank you very much. That's what I was missing. The word 'dynamic' is being misapplied :shock:

At run time, the .c type is neither growable nor mutable therefore by definition it is static, not dynamic. The compiler having a switch that changes .c's base allocation is independent of .c's capacity to store meaningful information; it's always a solitary char, irrespective of the compiler needing one or two bytes to represent that char.

Now I understand. You've solved the mystery. Thanks once again.
Post Reply