News for hackers. Stuff that matters.
Re:Checked C: extension to C that adds static and dynamic ch... by userbinator on Wednesday March 14, 2018 @09:18PM (#16589808)
I've used something similar --- a null-terminated string, with a length prefix at a negative offset. Resizeable ones have an "allocated size" field before that one. This makes for strings that are both easy to manipulate and compatible with existing functions that only read a regular C string.
Re:Checked C: extension to C that adds static and dynamic ch... by zzzcpan on Wednesday March 14, 2018 @09:27PM (#16589859)
Re:Checked C: extension to C that adds static and dynamic ch... by userbinator on Wednesday March 14, 2018 @09:44PM (#16589944)
Good to see I'm not the only one who thought of that idea, although my implementation has a different order of the fields (and IMHO better, since it allows for statically allocated strings with only a length field --- a sort of subclassing.)
Re:Checked C: extension to C that adds static and dynamic ch... by nikanj on Wednesday March 14, 2018 @11:31PM (#16590239)
So, BSTRs? They’re common in old-timey COM apis
Re:Checked C: extension to C that adds static and dynamic ch... by watersb on Thursday March 15, 2018 @04:02AM (#16591101)
BSTR size field is at positive offset, IIRC.
Re:Checked C: extension to C that adds static and dynamic ch... by nikanj on Friday March 16, 2018 @01:31PM (#16602317)
You do not RC :)
Re:Checked C: extension to C that adds static and dynamic ch... by timClicks on Wednesday March 14, 2018 @11:28PM (#16590228)
So in a sense implementing Pascal strings in C?
Re:Checked C: extension to C that adds static and dynamic ch... by flukus on Thursday March 15, 2018 @02:25AM (#16590804)
Yes. But also "abusing" C's permissiveness with pointers to get pascal strings that interop with standard functions. It get's passed around as a pointer to a char array but the length function would return the value at that pointer - sizeof(size_T). In most languages this wouldn't be possible.