![]() |
![]() |
#1 |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
Structures via pointers giving different results to direct dot access
i can't figure this out.
This code: Code:
void __Eurofighter_construct(void * _eurofighter /* position, orientation */) { KPrintF("In __Eurofighter_construct."); KPrintF("// these things work:"); BSPModelData * b = &eurofighterBSPModelData; KPrintF(" b->modelData.numVertices = %ld", b->modelData.numVertices); ModelData * m = (ModelData *) b; KPrintF(" m->numVertices = %ld", m->numVertices); KPrintF("// but this doesn't:"); KPrintF(" eurofighterBSPModelData.modelData.numVertices = %d", eurofighterBSPModelData.modelData.numVertices); KPrintF("Huh."); BSPModel * eurofighterModel = new_BSPModel(&eurofighterBSPModelData); __EntityWithModel_construct((EntityWithModel *) _eurofighter, /* position, orientation */ (Model *) eurofighterModel); } Code:
In __Eurofighter_construct. // these things work: b->modelData.numVertices = 52 m->numVertices = 52 // but this doesn't: eurofighterBSPModelData.modelData.numVertices = 0 Huh. The structure ModelData is defined like this: Code:
typedef struct modelData { UWORD numVertices; Point3D * vertices; } ModelData; Code:
typedef struct bspModelData { ModelData modelData; Section * bspTreeRoot; } BSPModelData; Code:
static BSPModelData eurofighterBSPModelData = { .modelData = { .numVertices = EUROFIGHTER_NUM_VERTICES, .vertices = vertices }, .bspTreeRoot = (Section *) &eurofighterSection }; Any ideas? |
![]() |
![]() |
#2 |
Total Chaos forever!
![]() Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 46
Posts: 1,644
|
Using a dot operator with a pointer requires you dereference using a star.
|
![]() |
![]() |
#3 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,218
|
KPrintF(" eurofighterBSPModelData.modelData.numVertices = %d"
This should read %ld, like in the other places. The code is correct, the debugging isn't. |
![]() |
![]() |
#4 |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
|
![]() |
![]() |
#5 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,218
|
In case you missed my post: your code is doing what you expect. Your debug output is wrong.
|
![]() |
![]() |
#6 | |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
Quote:
Code:
// but this doesn't: eurofighterBSPModelData.modelData.numVertices = 52 Huh. Thanks! |
|
![]() |
![]() |
#7 |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
Found it.
I had: Code:
Model * model = (Model *) model; Code:
Model * model = (Model *) _model; Code:
Model * wibble = (Model *) wibble; I think the best thing for me to do is to rework my variable naming to make this less likely to happen again. Edit: Code:
Model * wobble = wobble; Last edited by Ernst Blofeld; 23 November 2020 at 19:36. |
![]() |
![]() |
#8 |
Total Chaos forever!
![]() Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 46
Posts: 1,644
|
C isn't picky. It just assumes you are right even if you aren't.
|
![]() |
![]() |
#9 | |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,218
|
Quote:
The line is just a short form of Code:
Model *wibble; wibble = (Model *)wibble; What you really should do is to avoid all that casting. Use proper types for your variables. For example in your first post instead of ModelData *m = (ModelData *) b; you should use ModelData *m = &b->modelData; This way the compiller can help you. If you use casting you tell the compiler that you know better than him. But obviously you don't. |
|
![]() |
![]() |
#10 | |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
Quote:
|
|
![]() |
![]() |
#11 |
Registered User
![]() Join Date: Jun 2020
Location: Brno
Posts: 47
|
|
![]() |
![]() |
#12 |
<optimized out>
![]() Join Date: Sep 2020
Location: <optimized out>
Posts: 304
|
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Structures offsets | kamelito | Coders. System | 16 | 24 January 2021 07:26 |
It seem the JIT direct mode is not work in fs-uae. direct mode is important | bernd roesch | support.FS-UAE | 27 | 20 September 2015 21:44 |
Memory Data Structures | Zetr0 | support.Hardware | 7 | 30 September 2007 17:38 |
IFF/ILBM structures .... | freddix | Coders. General | 7 | 18 September 2006 09:54 |
Slow speed Direct HD access | Dan Andrea | support.WinUAE | 3 | 27 December 2002 14:21 |
|
|