TIP 528: Deprecate Tk_Offset()

Login
Author:         Jan Nijtmans <jan.nijtmans@gmail.com>
State:          Draft
Type:           Project
Vote:           Pending
Created:        05-Dec-2018
Post-History:   
Tcl-Version:    8.7
Tk-Branch:     offsetof

Abstract

This TIP proposes to deprecate Tk_Offset() in favour of offsetof().

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 type: Tk_Offset() gives an int while offsetof() gives 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, to make room for this enhancements. 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.