Differences between C++ and Smalltalk MT

Home | Up | Search | X-Zone News | Services | Book Support | Links | Feedback | Smalltalk MT | The Scrapyard | FAQ | Technical Articles

 

Syntax differences

Strings in Smalltalk MT are delimited by single quote e.g. 'Here is a string'. To embed a quote in a string, double it e.g. 'It''s here'.

Comments in Smalltalk MT use double quotes e.g. "Here is a comment". Or you can use /* and */ as in C.

Statements in Smalltalk MT end with a period.

Variables are not typed in Smalltalk MT. All variables hold an Object which knows it's type. Use | to declare variables. For example in a Workspace type

|var1|

var1 := Array new: 30. "This declares an Object of type Array and stores it in var1"
var1 class. "If you do a Display here, it will show Array. var1 knows its type"

In Smalltalk comma is used for concatenation. For example: 'abc','def' will concatenate two strings. This same operator will concatenate any two objects if they have the appropriate behaviour (e.g. two arrays).

Operator differences

Here is a table of some of the operator differences.

Operator Name or Meaning Associativity Smalltalk MT
:: Scope resolution None Same
:: Global None  
[ ] Array subscript Left to right send the message at:
( ) Function call Left to right No function calls
( ) Conversion None  
. Member selection (object) Left to right  
–> Member selection (pointer) Left to right  
++ Postfix increment None  
–– Postfix decrement None  
new Allocate object None  
delete Deallocate object None  
delete[ ] Deallocate object None  
++ Prefix increment None  
–– Prefix decrement None  
* Dereference None  
& Address-of None basicAddress
+ Unary plus None No unary plus
Arithmetic negation (unary) None Both available
! Logical NOT None not
~ Bitwise complement None  
sizeof Size of object None sizeInBytes
sizeof ( ) Size of type None sizeInBytes
typeid( ) type name None class
(type) Type cast (conversion) Right to left all casting is performed by sending messages e.g. asInteger, asFloat, asString etc.
const_cast Type cast (conversion) None See (type) above.
dynamic_cast Type cast (conversion) None See (type) above.
reinterpret_cast Type cast (conversion) None See (type) above.
static_cast Type cast (conversion) None See (type) above.
.* Apply pointer to class member (objects) Left to right  
–>* Dereference pointer to class member Left to right MemoryManager atAddress: aPointer.
* Multiplication Left to right *
/ Division Left to right / returns a fraction, a float or an integer depending on the arguments. // always returns an Integer
% Remainder (modulus) Left to right \\
+ Addition Left to right +
Subtraction Left to right -
<< Left shift Left to right <<
>> Right shift Left to right >>
< Less than Left to right <
> Greater than Left to right >
<= Less than or equal to Left to right <=
>= Greater than or equal to Left to right >=
== Equality Left to right == means the same identical Object. = means that the Objects compare the same.
!= Inequality Left to right ~=
& Bitwise AND Left to right &
^ Bitwise exclusive OR Left to right bitXor: anInteger
| Bitwise OR Left to right |
&& Logical AND Left to right &&
|| Logical OR Left to right or:
e1?e2:e3 Conditional Right to left e1 ifTrue: [e2] ifFalse: [e3]
= Assignment Right to left :=
*= Multiplication assignment Right to left a := a * b
/= Division assignment Right to left a := a / b
%= Modulus assignment Right to left a := a \\b
+= Addition assignment Right to left a := a + b.
= Subtraction assignment Right to left a := a - b.
<<= Left-shift assignment Right to left a := a << b.
>>= Right-shift assignment Right to left a := a >> b.
&= Bitwise AND assignment Right to left a := a & b.
|= Bitwise inclusive OR assignment Right to left a := a | b.
^= Bitwise exclusive OR assignment Right to left a := a xor: b.
, Comma Left to right concatenate

 

DLL differences

In C++, WINAPI calls are declared as extern and are bound in by the linker. In Smalltalk MT, libraries are bound into the running development environment. This has the advantage that API call can be executed in a workspace. To bind a library, go to the Transcript and use Image Properties (2nd icon from the right). Add your DLL. Check the list to make sure it was found. Now save your image (last icon on the right). When you restart your image, the DLL has been bound into your development environment. To try out an API call, open a workspace and type

WINAPI MessageBeep: -1

This calls the MessageBeep API in Kernel DLL.

Debugging

The simplest debugging approach is to use DBMON. To write to DBMON, use

Process outputDebugLine: 'Here is a debugging message'.

To include the value of a variable use

Processor outputDebugLine: 'Variable var1 has value ',var1 printString.

 

This site, created by DirectX MVP Robert Dunlop and aided by the work of other volunteers, provides a free on-line resource for DirectX programmers.

Special thanks to WWW.MVPS.ORG, for providing a permanent home for this site.

Visitors Since 1/1/2000: Hit Counter
Last updated: 07/26/05.