Author: Jan Nijtmans <[email protected]>
State: Final
Type: Project
Vote: Done
Created: 05-Dec-2018
Post-History:
Tcl-Version: 8.7
Tk-Branch: offsetof
Votes-For: DKF, BG, KBK, JN, DGP, FV, SL, AK
Votes-Against: none
Votes-Present: none
Abstract
This TIP proposes to deprecate Tk_Offset()
in favour of offsetof()
.
It will not be removed from the Tk headers, just from the documentation.
Rationale
The Tk_Offset()
macro comes from the past, when C's official offsetof()
macro didn't exist yet, or was not supported yet by all compilers.
The main difference between Tk_Offset()
and offsetof()
is the return type: Tk_Offset()
returns an int
while offsetof()
returns a size_t
. size_t
is actually
more correct, because it cannot become negative and it allows for values >= 4Gb on 64-bit platforms.
Proposed Change
This TIP proposes to deprecate the Tk_Offset()
macro. Starting with
Tk 8.7, when compiling an extension with the flag -DTK_NO_DEPRECATED
,
Tk_Offset()
will no longer be provided by tk.h. All occurrences
of Tk_Offset()
within Tk itself are replaced by offsetof()
.
This TIP doesn't propose to remove Tk_Offset()
altogether, since there
are too many extensions still using it.
Further on, it makes sense to change various struct member types from
int
to size_t
, so the size of the type matches the size returned
by offsetof()
. For reasons of upwards compatibility, providing a
smooth upgrade path, when compiling Tk against Tcl 8.x headers, the
type of those struct members will continue to be int
.
While on it, this TIP proposes to change the src
and dst
members
of Tk_ArgvInfo
from char *
to void *
. Although unrelated to
the other proposed changes, this allows various type casts to
be eliminated in the source code of Tk (and possibly in extensions).
Since those fields are used to store untyped pointers, this is
actually a bug-fix which should not need a TIP, but since it affects
the documentation it doesn't hurt to provide this change in a TIP anyway.
An implementation of this TIP can be found in the [offsetof] branch.
Copyright
This document has been placed in the public domain.