digitalmars.D - Even worse Array stuff
- Matthew (23/23) Jul 14 2004 ORJFieldA *begin = &record.fields[0];
- Ivan Senji (15/38) Jul 14 2004 chews. It
- Matthew (4/36) Jul 14 2004 I did wonder about that, but by that stage my keyboard had translated my
- Sean Kelly (12/24) Jul 14 2004 I had proposed this to Jill a few weeks ago in another thread. I'm not ...
ORJFieldA *begin = &record.fields[0]; ORJFieldA *end = begin + m_record.fields.length; for(; begin != end; ++begin) { Now it halts on the first line, when the record has no fields. :( Of course, it's obvious in hindsight. But that's hindsight. This really chews. It means that we have to eschew well-founded, widely used and entirely safe C++ coding practices. And before anyone says, use foreach, I can't because I need a pointer to the original structure in situ, rather than a copy. I tried the following earlier, and was not surprised to be receiving the address of a temporary in the Field ctor: foreach(ORJFieldA f; record.fields) { Field field = new Field(f); . . . } What do we think of the rule that array-bounds checking is not used when taking the address of the result? By taking its address, one puts oneself in the wild vistas of the C programmer, and the Spirit of C dictates that we trust the programmer? For the moment, though, I'll just have to clutter up my code with redundant conditionals ...
Jul 14 2004
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cd2n2n$l45$1 digitaldaemon.com...ORJFieldA *begin = &record.fields[0]; ORJFieldA *end = begin + m_record.fields.length; for(; begin != end; ++begin) { Now it halts on the first line, when the record has no fields. :( Of course, it's obvious in hindsight. But that's hindsight. This reallychews. Itmeans that we have to eschew well-founded, widely used and entirely safeC++coding practices. And before anyone says, use foreach, I can't because I need a pointer totheoriginal structure in situ, rather than a copy. I tried the followingearlier,and was not surprised to be receiving the address of a temporary in theFieldctor: foreach(ORJFieldA f; record.fields) { Field field = new Field(f);I could be wrong but have you tried: foreach(inout ORJFieldA f; record.fields) { ... i think this will give you the pointer to the original struct.. . . } What do we think of the rule that array-bounds checking is not used whentakingthe address of the result? By taking its address, one puts oneself in thewildvistas of the C programmer, and the Spirit of C dictates that we trust the programmer? For the moment, though, I'll just have to clutter up my code withredundantconditionals ...
Jul 14 2004
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cd2on8$o63$1 digitaldaemon.com..."Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cd2n2n$l45$1 digitaldaemon.com...I did wonder about that, but by that stage my keyboard had translated my impatience into the now working code. ;/ORJFieldA *begin = &record.fields[0]; ORJFieldA *end = begin + m_record.fields.length; for(; begin != end; ++begin) { Now it halts on the first line, when the record has no fields. :( Of course, it's obvious in hindsight. But that's hindsight. This reallychews. Itmeans that we have to eschew well-founded, widely used and entirely safeC++coding practices. And before anyone says, use foreach, I can't because I need a pointer totheoriginal structure in situ, rather than a copy. I tried the followingearlier,and was not surprised to be receiving the address of a temporary in theFieldctor: foreach(ORJFieldA f; record.fields) { Field field = new Field(f);I could be wrong but have you tried: foreach(inout ORJFieldA f; record.fields) { ... i think this will give you the pointer to the original struct.
Jul 14 2004
In article <cd2n2n$l45$1 digitaldaemon.com>, Matthew says...ORJFieldA *begin = &record.fields[0]; ORJFieldA *end = begin + m_record.fields.length; for(; begin != end; ++begin) { Now it halts on the first line, when the record has no fields. :( Of course, it's obvious in hindsight. But that's hindsight. This really chews. It means that we have to eschew well-founded, widely used and entirely safe C++ coding practices...What do we think of the rule that array-bounds checking is not used when taking the address of the result? By taking its address, one puts oneself in the wild vistas of the C programmer, and the Spirit of C dictates that we trust the programmer?I had proposed this to Jill a few weeks ago in another thread. I'm not sure I like it because it seems like a hack, but it would certainly work. Another temporary solution would be this: ORJFieldA *begin = m_records.length ? &record.fields[0] : null; ORJFieldA *end = begin + m_record.fields.length; for(; begin != end; ++begin) {} In some respects I do like this approach better because it doesn't result in pointers to uninitialized memory, but the dereferencing issue will still be a problem for folks trying to port C code. Sean
Jul 14 2004