Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-13
11:18 • Closed ticket [8fb059e8ec]: macro for sentinels plus 6 other changes artifact: c22148638a user: serhiy.storchaka
2024-04-25
12:05 • Ticket [8fb059e8ec]: 3 changes artifact: 371c2927d7 user: jan.nijtmans
11:58 • Ticket [8fb059e8ec]: 3 changes artifact: 43ab95ceda user: sebres
11:47 • Ticket [8fb059e8ec]: 3 changes artifact: 765d922da8 user: chw
11:06 • Ticket [8fb059e8ec]: 3 changes artifact: 2180f6540b user: jan.nijtmans
10:24 • Ticket [8fb059e8ec]: 3 changes artifact: 91d2337634 user: chw
09:55 • Ticket [8fb059e8ec]: 3 changes artifact: 724487369b user: jan.nijtmans
2024-04-24
16:12 • New ticket [8fb059e8ec]. artifact: dd35a93d40 user: dgp

macro for sentinels

Closed / Rejected8fb059e8ec2344cbc4a3b537ae752b13f310920bCreated 3 years agoUpdated 20 days ago
Descriptionplain2024-04-24 16:12:36
Recent check-in [c6d3960498] included a large number of changes where
a sentinel argument was changed from

  (void) NULL

to

  (char *) NULL

Would we get code maintenance benefit from a macro in a header file:

#define TCL_SENTINEL (char *) NULL

so we can make any similar future modifications in one place?
jan.nijtmanswiki2024-04-25 09:55:03

Actually, it was changed from (void *)NULL to (char *)NULL. The reason for this is just readability: It is used in functions like Tcl_SetErrorCode(), Tcl_AppendResult(), and Tcl_AppendStringsToObj(), which expect strings in all its elements. Using (char *)NULL makes it immediately clear that the last sentinel argument is a string too.

Using TCL_SENTINEL would hide that information, I don't think we want that. In functions like mp_init_multi() sentinels are used as well, but there the arguments are not strings. Therefore (void *)NULL is kept there: It could have been changed to (mp_int *)NULL, but that looks more ugly.

Just my 2c

chwplain2024-04-25 10:24:13
Can't resist to throw my 2 cents into this debate.
Few months ago we had a similar discussion about the cons and pros
of TCL_UNUSED and my argument against it was information loss.
Now, the use of TCL_SENTINEL is information loss, too, and arguably
not favorable?
Am I the only one who's somewhat puzzled?
jan.nijtmanswiki2024-04-25 11:06:24

lol. So you would prefer `TCL_SENTINEL(char *)` then ??

The difference with TCL_UNUSED is that C/C++ already has the standard construct `(type)NULL` for exactly what we want here.

That 2 more cents, making 6 ;-)

chwplain2024-04-25 11:47:27
Lemme be clear, neither do I like TCL_UNUSED, nor TCL_SENTINEL.
Both hide in my irrelevant opinion information. But if that is
culturally common sense, so be it and I need to get used to it
and finally have to live with it.
sebresmarkdown2024-04-25 11:58:22

Is it really necessary to switch cast from (char *)NULL to (void *)NULL?
I mean isn't void * compatible with (char *)NULL? And from point of view the functions with variadic args like Tcl_AppendResult it is also the same thing.
So let it be (char *)NULL everywhere - no changes across versions, no conflicts, no special sentinel macro needed...

jan.nijtmanswiki2024-04-25 12:05:09

> So let it be (char *)NULL everywhere - no changes across versions, no conflicts, no special sentinel macro needed...

Yes, that's the idea....

serhiy.storchakawiki2026-11-13 11:18:45

Closing: the consensus above was to keep the explicit (char *)NULL sentinels.

Log in (anonymous is fine) to add a comment.