mirror of
https://github.com/cc65/cc65.git
synced 2024-07-05 21:29:03 +00:00
Clarify calling order for constructors/destructors
git-svn-id: svn://svn.cc65.org/cc65/trunk@2266 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
f28586ffcc
commit
53dc9dedf0
@ -846,16 +846,16 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
id=".DESTRUCTOR" name=".DESTRUCTOR"></tt> commands are actually shortcuts
|
id=".DESTRUCTOR" name=".DESTRUCTOR"></tt> commands are actually shortcuts
|
||||||
for <tt/.CONDES/ with a type of <tt/constructor/ resp. <tt/destructor/.
|
for <tt/.CONDES/ with a type of <tt/constructor/ resp. <tt/destructor/.
|
||||||
|
|
||||||
After the type, an optional priority may be specified. If no priority is
|
After the type, an optional priority may be specified. Higher numeric values
|
||||||
given, the default priority of 7 is used. Be careful when assigning
|
mean higher priority. If no priority is given, the default priority of 7 is
|
||||||
priorities to your own module constructors so they won't interfere with the
|
used. Be careful when assigning priorities to your own module constructors
|
||||||
ones in the cc65 library.
|
so they won't interfere with the ones in the cc65 library.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<tscreen><verb>
|
<tscreen><verb>
|
||||||
.condes ModuleInit, constructor
|
.condes ModuleInit, constructor
|
||||||
.condes ModInit, 0, 16
|
.condes ModInit, 0, 16
|
||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
See the <tt><ref id=".CONSTRUCTOR" name=".CONSTRUCTOR"></tt> and <tt><ref
|
See the <tt><ref id=".CONSTRUCTOR" name=".CONSTRUCTOR"></tt> and <tt><ref
|
||||||
@ -911,9 +911,10 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
A constructor is always exported as an absolute (16 bit) symbol. You don't
|
A constructor is always exported as an absolute (16 bit) symbol. You don't
|
||||||
need to use an additional <tt/.export/ statement, this is implied by
|
need to use an additional <tt/.export/ statement, this is implied by
|
||||||
<tt/.constructor/. It may have an optional priority that is separated by a
|
<tt/.constructor/. It may have an optional priority that is separated by a
|
||||||
comma. If no priority is given, the default priority of 7 is used. Be
|
comma. Higher numeric values mean a higher priority. If no priority is
|
||||||
careful when assigning priorities to your own module constructors so they
|
given, the default priority of 7 is used. Be careful when assigning
|
||||||
won't interfere with the ones in the cc65 library.
|
priorities to your own module constructors so they won't interfere with the
|
||||||
|
ones in the cc65 library.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@ -1041,9 +1042,10 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
A destructor is always exported as an absolute (16 bit) symbol. You don't
|
A destructor is always exported as an absolute (16 bit) symbol. You don't
|
||||||
need to use an additional <tt/.export/ statement, this is implied by
|
need to use an additional <tt/.export/ statement, this is implied by
|
||||||
<tt/.destructor/. It may have an optional priority that is separated by a
|
<tt/.destructor/. It may have an optional priority that is separated by a
|
||||||
comma. If no priority is given, the default priority of 7 is used. Be
|
comma. Higher numerical values mean a higher priority. If no priority is
|
||||||
careful when assigning priorities to your own module destructors so they
|
given, the default priority of 7 is used. Be careful when assigning
|
||||||
won't interfere with the ones in the cc65 library.
|
priorities to your own module destructors so they won't interfere with the
|
||||||
|
ones in the cc65 library.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@ -2266,7 +2268,7 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
"proprietary and confidential".
|
"proprietary and confidential".
|
||||||
|
|
||||||
See: <tt><ref id=".P02" name=".P02"></tt>, <tt><ref id=".PSC02"
|
See: <tt><ref id=".P02" name=".P02"></tt>, <tt><ref id=".PSC02"
|
||||||
name=".PSC02"></tt>, <tt><ref id=".PC02" name=".PC02"></tt>, and
|
name=".PSC02"></tt>, <tt><ref id=".PC02" name=".PC02"></tt>, and
|
||||||
<tt><ref id=".P816" name=".P816"></tt>
|
<tt><ref id=".P816" name=".P816"></tt>
|
||||||
|
|
||||||
|
|
||||||
@ -2843,6 +2845,19 @@ two bytes in the table (a pointer to the function).
|
|||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
|
|
||||||
|
<sect1>Calling order<p>
|
||||||
|
|
||||||
|
Both, constructors and destructors are sorted in increasing priority order by
|
||||||
|
the linker when using one of the builtin linker configurations, so the
|
||||||
|
functions with lower priorities come first and are followed by those with
|
||||||
|
higher priorities. The C library runtime subroutine that walks over the
|
||||||
|
constructor and destructor tables calls the functions starting from the top of
|
||||||
|
the table - which means that functions with a high priority are called first.
|
||||||
|
|
||||||
|
So when using the C runtime, both constructors and destructors are called with
|
||||||
|
high priority functions first, followed by low priority functions.
|
||||||
|
|
||||||
|
|
||||||
<sect1>Pitfalls<p>
|
<sect1>Pitfalls<p>
|
||||||
|
|
||||||
When creating and using module constructors and destructors, please take care
|
When creating and using module constructors and destructors, please take care
|
||||||
|
Loading…
Reference in New Issue
Block a user