Back: CSmalltalk-accessing
Up: Class reference
Forward: CString class-getting info
 
Top: GNU Smalltalk User's Guide
Contents: Table of Contents
Index: Class index
About: About this document

6.44 CString

Defined in namespace Smalltalk
Category: Language-C interface
Technically, CString is really a pointer to type char. However, it's so darn useful as a distinct datatype, and it is a separate datatype in Smalltalk, so we allow developers to express their semantics more precisely by using a more descriptive type.

In general, I behave like a cross between an array of characters and a pointer to a character. I provide the protocol for both data types. My #value method returns a Smalltalk String, as you would expect for a scalar datatype.

6.44.1 CString class: getting info  (class)
6.44.2 CString: accessing  (instance)
6.44.3 CString: pointer like behavior  (instance)


6.44.1 CString class: getting info

alignof
Answer the receiver's instances required aligment

scalarIndex
Private - Answer an index referring to the receiver's instances scalar type

sizeof
Answer the receiver's size


6.44.2 CString: accessing

alignof
Answer the receiver's required aligment

scalarIndex
Private - Answer an index referring to the receiver's scalar type

sizeof
Answer the receiver's size


6.44.3 CString: pointer like behavior

+ anInteger
Return another CString pointing at &receiver[anInteger] (or, if you prefer, what `receiver + anInteger' does in C).

- intOrPtr
If intOrPtr is an integer, return another CString pointing at &receiver[-anInteger] (or, if you prefer, what `receiver - anInteger' does in C). If it is a CString, return the difference in chars, i.e. in bytes, between the two pointed addresses (or, if you prefer, what `receiver - anotherCharPtr' does in C)

addressAt: anIndex
Access the string, returning a Smalltalk CChar corresponding to the given indexed element of the string. anIndex is zero-based, just like with all other C-style accessing.

at: anIndex
Access the string, returning the Smalltalk Character corresponding to the given indexed element of the string. anIndex is zero-based, just like with all other C-style accessing.

at: anIndex put: aCharacter
Store in the string a Smalltalk Character, at the given indexed element of the string. anIndex is zero-based, just like with all other C-style accessing.

decr
Adjust the pointer by one byte down (i.e. --receiver)

decrBy: anInteger
Adjust the pointer by anInteger bytes down (i.e. receiver -= anInteger). Note that, unlike #-, #decrBy: does not support passing another CString as its parameter, since neither C supports something like `charPtr -= anotherCharPtr'

deref
Access the string, returning the Smalltalk CChar corresponding to the first element of the string. This may not make much sense, but it resembles what `*string' does in C.

deref: aCChar
Access the string, setting the first element of the string to the value of the passed CChar. This may not make much sense, but it resembles what we get in C if we do *string = 's'.

incr
Adjust the pointer by one byte up (i.e. ++receiver)

incrBy: anInteger
Adjust the pointer by anInteger bytes up (i.e. receiver += anInteger)

replaceWith: aString
Overwrite memory starting at the receiver's address, with the contents of the Smalltalk String aString, null-terminating it. Ensure there is free space enough, or big trouble will hit you!




This document was generated on May, 12 2002 using texi2html