Some variables can be initialised using constants in their declarations. The variables you cannot initialise in this way are array and complex type variables (and procedure parameters, obviously). All the other kinds can be initialised, whether they are local or global. An initialised declaration looks very much like a constant definition, with the value following the variable name and a `=' character joining them. The following example illustrates initialised declarations:
SET ENGLISH, FRENCH, GERMAN, JAPANESE, RUSSIAN CONST FREDLANGS=ENGLISH OR FRENCH OR GERMAN DEF fredspeak=FREDLANGS, p=NIL:PTR TO LONG, q=0:PTR TO rec PROC fred() DEF x=1, y=88 /* Rest of procedure */ ENDPROC
Notice how you need to use a constant like
FREDLANGS in order to initialise the declaration of
fredspeak to something mildly complicated.
Also, notice the initialisation of the pointers
q, and the position of the type information.
Of course, if you want to initialise variables with anything more than a simple constant you can use assignments at the start of the code. Generally, you should always initialise your variables (using either method) so that they are guaranteed to have a sensible value when you use them. Using the value of a variable that you haven't initialised in some way will probably get you in to a lot of trouble, because the value will just be something random that happened to be in the memory which is now being used by the variable. There are rules for how E initialises some kinds of variables (see the Reference Manual, but it's wise to explicitly initialise even those, as (strangely enough!) this will make your program more readable.
Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.