[EE] Ideas about improving safety in C language
Isaac Marino Bavaresco <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <[email protected]> |
Hi folks, I was thinking about the current discussion about C/C++ language safety, and I recalled an old idea I had long ago about creating a new string format and library. It could be possible for one person alone to implement and use it privately, but of course it would be even better if it becomes a standard, perhaps with support from the compilers. I don't know whether something similar was already suggested or is being used, but I would like to know your opinion about it. Cheers, Isaac Proposed New C string format: Bytes: <descriptor> [<references_counter>] <allocated_size_indicator> [<used_size_indicator> [<number_of_characters>]] [<characters>...] Descriptor: (bits) 0aabbccr (bit seven is reserved to indicate future new formats, most probably two-byte descriptors) It would be good to have an encoding field (to indicate ASCII, ANSI, UTF-8, UTF-16, etc.), but there is not enough bits in a byte and the fields I chose are more important. Perhaps it can be included in a two-byte descriptor format. Some details like the obligatory presence of an ending '\0' character or not must be discussed. If the ending '\0' is required, it would be very simple to use the new format with the traditional C library functions. aa = Area: 00 Static 01 Stack (automatic) 10 Dynamic 11 Dynamic with references counter bb = Length Indicators Bits 00 8 bits 01 16 bits 10 32 bits 11 64 bits (perhaps this value could be used for other purpose, most probably 64-bits will never be used). cc = Length Indicators Present 00 Only Allocated Size Indicator (used for read-only or fixed size strings) 01 Allocated Size and Used Size Indicators 10 Allocated Size, Used Size and Number of Characters Indicators 11 *Reserved* Size Indicators: All-ones means not informed. Could be used so the length is to be calculated when the string is accessed for the first time, saving the need for calculating the length of every string in advance. It would require '\0' ended strings. Needs more thought. r = Read Only 0 Read-Write 1 Read-Only -- O software antivírus Avast realizou uma checagem de vírus neste e-mail. www.avast.com -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at https://mailman.mit.edu/mailman/listinfo/piclist