Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
116 user(s) are online (79 user(s) are browsing Forums)

Members: 0
Guests: 116

more...

Headlines

 
  Register To Post  

[Fixed] GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
Hi,

I have cleaned up a bit my actual AmiDARK Engine source code but there are 2 warnings I cannot fix.

Warning #1:
AmiDE_Libs/Basic3D.c:212:warning:assignment makes integer from pointer without a case

Source Code :
void AddObjectToListint ObjectIDObject3DType *ObjectPTR ){
  
int *ObjectPTR2;
  
ObjectPTR2 = (int *)ObjectPTR;
  if ( 
ObjectID ){
    
// Si la liste des objets 3D ne contient pas assez d'elements on l'agrandit.
    
if (Basic3D.ObjectListAmount ObjectID ){
      
ResizeObjectListObjectID );
     }
    
// Add the object into the object list.
    
int *NewObjectListPTR;
    
NewObjectListPTR Basic3D.ObjectList + ( ObjectID sizeof( int ) );
    *
NewObjectListPTR ObjectPTR2;  // LINE 212 IS HERE //
    
++Basic3D.ObjectAmount;
   }
 }


Additionnal informations : Object3DType definition :
struct Object3DStruct{
  
BOOL Exist;
  
int ID;
  
int Type;
  
float XPosYPosZPos;
  
float XRotYRotZRot;
  
float XScaleYScaleZScale;
  
int ImageIndex;
  
BOOL HiddenCullingTransparencyWireFrameFogAmbientLightsFiltering;
  
float RGBRedRGBGreenRGBBlue;
  
BOOL IsGhost;
  
int GhostMode;
  
int DiffuseAmbienceSpecularEmissiveSpecularPower;
  
int DetailMappingImageSmoothingAlphaMappingPercent;
  
int *MeshDataPtr;
  
int MeshMemorySize;
 };
typedef struct Object3DStruct Object3DType;


Warning #2:
AmiDE_Libs/Basic3D.c:245: warning: "NewObjectPTR" may be used uninitialized in this function
AmiDE_Libs/Basic3D.c:245: note: "NewObjectPTR' was declared here

Source Code :
Object3DType *GetObjectPTRint ObjectID ){
  
int *ObjectListPTR;
  
Object3DType *NewObjectPTR;  // LINE 245 IS HERE
  
if ( ObjectID ){
    if ( 
ObjectID <= Basic3D.ObjectAmount ){
      
ObjectListPTR Basic3D.ObjectList;
      
ObjectListPTR ObjectListPTR + ( sizeof( int ) * ObjectID );
      
NewObjectPTR = (Object3DType *)*ObjectListPTR;
     }
   }
  return 
NewObjectPTR;
 }


Does someone have a solution ?

Thank you.
Kindest Regards,
AmiDARK


Edited by freddix on 2009/9/17 1:53:23
All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC Compilation warnings I cannot fix
Supreme Council
Supreme Council


See User information
@freddix

Don't have time to look into all of this but #2 should be easy to solve.

Quote:

Warning #2:
AmiDE_Libs/Basic3D.c:245: warning: "NewObjectPTR" may be used uninitialized in this function
AmiDE_Libs/Basic3D.c:245: note: "NewObjectPTR' was declared here


It complains because you try to return the NewObjectPTR without ever assigning a value to it. That is, the code inside the if statements may not be executed at runtime, ie the pointer is never assigned. Just assign null/zero to the pointer declaration and it should stop complaining. Just be sure that anyone calling the function can deal with a returning null pointer.

Vacca foeda. Sum, ergo edo

Mr Bobo Cornwater
Go to top
Re: GCC Compilation warnings I cannot fix
Not too shy to talk
Not too shy to talk


See User information
@freddix

Quote:

int *ObjectPTR2;
int *NewObjectListPTR;
*NewObjectListPTR = ObjectPTR2; // LINE 212 IS HERE //


This really should be obvious.

NewObjectListPTR is a pointer to an int, so *NewObjectListPTR is an int. You assign ObjectPTR2, which is a pointer, to that int.

I am not sure what this line actually shall do. If the code works correctly, you could do something like

*NewObjectListPTR = (int)ObjectPTR2;

but that would only prove that you don't know yourself what the code is doing.

Better declare all variables so that it works without a cast.

Bye,
Thomas

Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@thomas
*NewObjectListPTR is a pointer to a list of pointers.
in fact with this function I must return the pointers of the choosen object in memory ( int ObjectID )/
An object is defined like in the Object3DType structure.

That's why I want to make ObjectPTR2 to point to the adress contained where NewObjectListPTR is.

Do you understand ?

Regards,
AmiDARK

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@freddix

If I were you I would rewrite AddObjectToList like that :

void AddObjectToListint ObjectIDObject3DType *ObjectPTR ){
  if ( 
ObjectID ){
    
// Si la liste des objets 3D ne contient pas assez d'elements on l'agrandit.
    
if (Basic3D.ObjectListAmount ObjectID ){
      
ResizeObjectListObjectID );
     }
    
// Add the object into the object list.
    
Basic3D.ObjectList[ObjectID] = ObjectPTR;
    ++
Basic3D.ObjectAmount;
   }
 }


and GetObjectPTR like that :
Object3DType *GetObjectPTRint ObjectID ){
  
Object3DType *NewObjectPTR null;
  if ( 
ObjectID ){
    if ( 
ObjectID <= Basic3D.ObjectAmount ){
      
NewObjectPTR Basic3D.ObjectList[ObjectID];
     }
   }
  return 
NewObjectPTR;
 }


Now dont forget to change ObjectList definition in Basic3D from type int * to type Object3DType * it should solve all your warnings.

Back to a quiet home... At last
Go to top
Re: GCC Compilation warnings I cannot fix
Not too shy to talk
Not too shy to talk


See User information
@freddix

Quote:
*NewObjectListPTR is a pointer to a list of pointers.


That's not what you told the compiler.

If you declare a variable like this:

type *var;

then "var" is a pointer to "type". And if you later reference "*var" then this means you are referencing the "type" which "var" points to. If "type" is int, then you reference an int.

Bye,
Thomas

Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@thomas
I have resolved my last warning by doing this :
void AddObjectToListint ObjectIDObject3DType *ObjectPTR ){
  if ( 
ObjectID ){
    
// Si la liste des objets 3D ne contient pas assez d'elements on l'agrandit.
    
if (Basic3D.ObjectListAmount ObjectID ){
      
ResizeObjectListObjectID );
     }
    
// Add the object into the object list.
    
int *NewObjectListPTR;
    
NewObjectListPTR Basic3D.ObjectList + ( ObjectID sizeof( int ) );
    *
NewObjectListPTR = (int)ObjectPTR;
    ++
Basic3D.ObjectAmount;
   }
 }

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@freddix

I am not sure what you are trying to do, I find my version a lot easier to read and understand than your :
- Basic3D.ObjectList is a list of Object3DType, hence I prefer to declare it accordingly :
struct Basic3D {
...
Object3DType ObjectList;
...
};
instead of declaring it as int *
- you want to store/retrieve an object from this list by its ID (in fact its index in the aforementioned list) thus why not use the [] operator which exists exactlly for this purpose.

After that all you have to do is allocate/deallocate memory for ObjectList using
- ANSI version :
ObjectList = (Object3DType *)mallocsizeof(Object3DType)* nb_objects );

- Amiga version :
ObjectList = (Object3DType *)IExec->AllocVecTags(sizeof(Object3DType*) * nb_objects );

and for deallocating :
- ANSI version :
free(ObjectList);

- Amiga version :
IExec->FreeVec(ObjectList);


FYI assuming pointers have same size as int might not work everywhere especially when/if we go to 64bits... If you need to go generic prefer using void* instead of int* that will be more readable (if you go Amiga only route the exec's type APTR is exactly that : a pointer to any datatype)

Back to a quiet home... At last
Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@abalaban
In fact, ObjectList is a memory location that'll contain pointers to objects structures:

Offset 0 : unused
Offset 4 : *Object1
Offset 8 : *Object2
Offset12: *Object3
Offset16: *Object4
Offset20: *Object5
...
...
Offset 4*n: *Objectn

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@freddix

Okay then what I wrote above is wrong : you should have ObjectList defined as an Object3DType **, i.e. an array of pointer to Object3DType

what i can suggest you if you have problems with the ** notation is to use an intermediate type like
typedef Object3DType Object3DPointer;
then your list becomes an array of Object3DPointer using the notation :
Object3DPointer ObjectList;
and you can then write
void AddObjectToListint ObjectIDObject3DPointer ObjectPTR ){
  if ( 
ObjectID ){
    
// Si la liste des objets 3D ne contient pas assez d'elements on l'agrandit.
    
if (Basic3D.ObjectListAmount ObjectID ){
      
ResizeObjectListObjectID );
     }
    
// Add the object into the object list.
    
Basic3D.ObjectList[ObjectID] = ObjectPTR;
    ++
Basic3D.ObjectAmount;
   }
 }

Object3DPointer GetObjectPTRint ObjectID ){
  
Object3DPointer NewObjectPTR null;
  if ( 
ObjectID ){
    if ( 
ObjectID <= Basic3D.ObjectAmount ){
      
NewObjectPTR Basic3D.ObjectList[ObjectID];
     }
   }
  return 
NewObjectPTR;
 }


FYI the operator [] is automatically calculating with the right offset when using xxx[12] it's in fact the same as writing xxx + 12 * sizeof(<xxx pointer type>).

Good luck with your project.

Back to a quiet home... At last
Go to top
Re: GCC Compilation warnings I cannot fix
Quite a regular
Quite a regular


See User information
@abalaban
Thank you for your explanation.
I know simple use of pointers but pointers or pointers was a bit obscure for me.
Your sample seem clear for me :)

I will use this solution that seem really simple of use.

EDIT : Just one additional note.
The list can be deleted and redefined (if user enter a bigger object number, greater than the list can contain, I create a new list (and delete the old one after having it copied in the new) ...
That's why I'll not change my Basic3D.ObjectList to an arrayr but I'll do that inside the function with an other data to do this job.

if I'm not wrong, it should give this result :
void AddObjectToListint ObjectIDObject3DPointer ObjectPTR ){
  
Object3DPointer ObjectList;
  
ObjectList Basic3D.ObjectList;
  if ( 
ObjectID ){
    if (
Basic3D.ObjectListAmount ObjectID ){
      
ResizeObjectListObjectID );
     ]
    
ObjectListObjectID ] = ObjectPTR;
   }
 }


and this :
Object3DPointer *GetObjectPTRint ObjectID ){
  
Object3DPointer NewObjectPTR null;
  
Object3DPointer ObjectList;
  
ObjectList Basic3D.ObjectList;
  if ( 
ObjectID ){
    if ( 
ObjectID <= Basic3D.ObjectAmount ){
      
NewObjectPTR ObjectListObjectID ];
     }
   }
  return 
NewObjectPTR;
 }


Erf !
With these changes ... Many new warning appear :( I'll h
have to fix them :(

EDIT 18.09.09 : I had to do some changes on my source code (due to the use of Object3DPointer now :p) ... Now it's entirely fixed again :) and all seem to function.

Thank you all

Regards,
Fred


Edited by freddix on 2009/9/17 18:52:38
Edited by freddix on 2009/9/17 18:55:27
Edited by freddix on 2009/9/17 18:59:17
Edited by freddix on 2009/9/17 18:59:57
Edited by freddix on 2009/9/18 0:54:58
Edited by freddix on 2009/9/18 9:43:00
All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 2 ( 0 members and 2 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project