- Reset struct or class sections - 5 Updates
- [newbie] visibility among files - 1 Update
- Open Source: The Good, Bad and Ugly — Studies in Two Extremes - 1 Update
- C++ question - 4 Updates
- auto return type - 7 Updates
| Bart <bc@freeuk.com>: Jun 30 09:31PM +0100 On 30/06/2018 18:44, Rick C. Hodgin wrote: >> For example, for 'floats' section, define a dummy struct with the same >> layout, and then do manipulations with pointers. > And the ei/ef union? typedef struct { union { int ei; float ef; } float f; float g; float h; } floats_section; struct SExample X; floats_section* X_floats = (void*)&X.ei; memset(X_floats,0,sizeof (*X_floats)); -- bart |
| "Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 30 04:56PM -0400 On 6/30/2018 4:31 PM, Bart wrote: > struct SExample X; > floats_section* X_floats = (void*)&X.ei; > memset(X_floats,0,sizeof (*X_floats)); The union was also defined in the integers {{..}} section. How would you allow a reset floats; and a reset integers; to reset the overlapping portions? Note: they overlap in the ++++ section below: // With section references: struct SExample { section linklist {{ struct SLinkList ll1; struct SLinkList ll2; }} // Since this one is not nested, doesn't need closing // "section linklist" text section data {{ --------section integers {{------- int a; | int b; | int c; | int d; | ========section floats {{========|====== union { +++++++| | int ei; +++++++| | overlapping data float ef; +++++++| | between sections } +++++++| | --------section integers }}------- | float f; | float g; | float h; | ========section floats }}=============== section data }} }; -- Rick C. Hodgin |
| Bart <bc@freeuk.com>: Jun 30 11:17PM +0100 On 30/06/2018 21:56, Rick C. Hodgin wrote: > ========section floats }}=============== > section data }} > }; The requirement is to clear everything in the integers section, or everything in the floats section? The simple way is to individually clear {a,b,c,d,ei/ef} or {ei/ef,f,g,h}. Another way is to duplicate the layout of {a,b,c,d,ei/ef} and {ei/ef,f,g,h} as I tried above (paying attention to alignments and padding). This defines object layouts that match your two sections. Another way is to divide your overlapping sections into three lots, each of which may be wrapped in an anonymous struct: A, B, C where section integers is {A, B}, and section floats is {B, C}. And A is {a,b,c,d}, B is {ei/ef} and C is {f,g,h}. Then you do reset A; reset B, or reset B; reset C. I'm sure other people can came up with many ways of actually performing the task. But devising a scheme for arbitrary, overlapping overlays to be added as a totally new language feature is quite hard to do, it will look ugly, and it will be confusing. If you want a more general approach within the current language, try this: #define integers_sect a,f #define floats_sect ei,i // dummy zero-size field after h struct SExample X; reset_section(&X,getoffsets(struct SExample,integers_sect)); where: #define getoffsets(T,a,b) offsetof(T,a),offsetof(T,b)-offsetof(T,a) This should yield 'x,y' where x is the start offset of the section, y is the size in bytes. The reset_section call becomes: reset_section(&X, 24, 16); for example. (This can map to memset((char*)&X+24,0,16).) I've no idea whether this would work, but this anyway has the problem of needing a struct field one past the end of the 'section'. But I think it won't appeal to you because the information that defines the sections is defined outside, separately from the struct. -- bart |
| "Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 30 06:45PM -0400 On 06/30/2018 06:17 PM, Bart wrote: > But devising a scheme for arbitrary, overlapping overlays to be added as > a totally new language feature is quite hard to do, it will look ugly, > and it will be confusing. I devised it. And it's not ugly or confusing. With syntax highlighting applied there are color bars which differentiate each grouping, and the section headers are hidden. Have you ever noticed that (nearly?) every feature I suggest or propose is criticized by you in your replies? It's a bad idea as I propose it, or it doesn't add enough value to be useful, or its just clutters up something, etc.? I was asking for a way to already do this in C so I wouldn't have to create one. But I do have a need for this ability, and it's not that difficult to add to the compiler, and I can see it have great utility when you stop and give the potential uses some thought. -- Rick C. Hodgin |
| "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Jun 30 04:02PM -0700 On 6/30/2018 6:45 AM, Rick C. Hodgin wrote: > linked list pointers), etc. > Does anyone know of a way in C where I could easily reset portions of > the structure contents in a reliable way? [...] quick pseudo-code ____________________________ struct part_0 { int a; }; struct part_1 { short b; }; struct parts { struct part_0 p0; struct part_1 p1; // other parts... }; Alter a portion of the structure: struct parts p = { { 12 }, { 34 } }; p.p1.b = 42; ____________________________ ;^) |
| Soviet_Mario <SovietMario@CCCP.MIR>: Jul 01 12:18AM +0200 I left C++ quite some years ago and now that I'm beginning again (QT Creator IDE) I can no longer have control over scope among files. I was used to separate code in different files, but it seems that I have some wrong setting (maybe in the makefile self-generated by QT, the errors are on linking) I've tried to include the .CPP files besides the normal .H files (with the normal protection against multiple inclusion, #ifndef #define
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment