Skip navigation.
 
ml[OT] Re: programming in C++ ?
FROM : Alastair Houghton
DATE : Sun Feb 03 19:16:54 2008

On 3 Feb 2008, at 16:44, Thomas Engelmeier wrote:

> On 01.02.2008, at 18:35, John Stiles wrote:
>

>> Well, most C++ code should be using new and not malloc() anyway. 
>> malloc() is a holdover from the Bad Untyped Days of C.

>
> That particular API has some semantics that proliverate bad 
> programming practice, anyway - structs with trailing variable length 
> data buffers. A lot of C casts, offsetof and whatever.


Structs with variable length data buffers are not "bad programming 
practice".

You may not *like* them, but that's different from them being 
inherently bad, even if it's a sentiment shared by many others.  In 
some circumstances they are the best way to solve a problem.  This is 
primarily the case where the overhead from keeping the variable length 
data separate would be too high; a straightforward example is with 
strings, which are *often* represented with a struct with variable-
length trailing data.  (Indeed, I think NS/CFString does exactly this 
in some cases.)

Put another way, eschewing malloc() or variable length structs in all 
situations is not pragmatic---it's dogmatic, and that's never a good 
way to make a decision.

Kind regards,

Alastair.

--
http://alastairs-place.net

Related mailsAuthorDate
mlRe: programming in C++ ? John Stiles Jan 30, 16:22
mlprogramming in C++ ? Cor Jan 31, 00:17
mlRe: programming in C++ ? Vance Jan 31, 00:42
mlRe: programming in C++ ? Uli Kusterer Jan 31, 00:53
mlRe: programming in C++ ? John Stiles Jan 31, 01:00
mlRe: programming in C++ ? Thomas Engelmeier Jan 31, 09:22
mlRe: programming in C++ ? Jiva DeVoe Jan 31, 16:17
mlRe: programming in C++ ? Shawn Erickson Jan 31, 17:39
mlRe: programming in C++ ? Shawn Erickson Jan 31, 17:40
mlRe: programming in C++ ? John Stiles Jan 31, 18:25
mlRe: programming in C++ ? Kevin Elliott Jan 31, 19:17
mlRe: programming in C++ ? Jay Reynolds Freem… Jan 31, 19:20
mlRe: programming in C++ ? Thomas Engelmeier Feb 1, 12:13
mlRe: programming in C++ ? John Stiles Feb 1, 18:35
mlRe: programming in C++ ? Thomas Engelmeier Feb 3, 17:44
ml[OT] Re: programming in C++ ? Alastair Houghton Feb 3, 19:16