Tcl Library Source Code

View Ticket
Login
Ticket UUID: 5613c718c2a648f85bac730aacb7db52250d6101
Title: Fixing compiler-warnings in C-code
Type: Bug Version: 1.17
Submitter: mi Created on: 2015-05-28 01:34:50
Subsystem: Build System & Testing Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2015-05-28 13:15:46
Resolution: None Closed By: nobody
    Closed on:
Description:

When using critcl, a number of warnings -- and bugs -- surface. Especially, when a "picky" compiler is in use -- such as clang, which is now the base "cc" on FreeBSD.

The fixes fall into several broad categories:

  1. Casting pointer to int needs to be done via intptr_t or else a warning is generated on platforms, where pointer and int are of different width.
  2. size_t is a better type for counters, than long int. Note, that no type is safe, if the counter can grow perpetually (as the enumerated objects are deleted and created) — sooner or later it will reset back to 0 (or MIN_LONG) causing mayhem. But, at least, with an unsigned type you will not have a - in the name. Generally speaking, this use of counters stinks and the actual pointers should be used instead, when a textual name for an object is desired sprintf(buf, "struct%p", pointer);
  3. Use "%td" to print the above counters.
  4. The function rde_param_query_lstop was outright broken — returning a junk instead of the value. Unlike Tcl, C does not implicitly return the result of the last invoked function :-)
  5. Faster implementation of UniCharIsDecDigit and UniCharIsHexDigit
  6. Include the right headers to make sure, every function used is declared in advance.
  7. Fixes to the test-data to account for all of the above
Some of the above changes assume C99 compiler. I believe that to be a reasonable assumption in 2015.

User Comments: mi added on 2015-05-28 13:15:46:

size_t should not a problem even on the ancient computers. For intptr_t, maybe, there is some kind of Tcl_Foo-equivalent?


aku added on 2015-05-28 06:06:19:

Applied patch into branch [<a href='timeline?r=tkt-5613c718c2-cwarnings&unhide'>tkt-5613c718c2-cwarnings</a>].

Missing the 'return' in "..._lstop". How embarrassing.

Regarding C99 in 2015, I will check what the native cc's of AIX, HPUX, and Solaris (2.8, 2.10) will say about the patched code. I suspect that at least one of these will choke on the size_t and intptr_t types, being more C89 than C99.


Attachments: