struct Matrix_4x4
{
float M[4][4]; //4 columns, 4 rows
};
This struct is defined in my .cpp file. I would like to be able to include a .h file which declares the struct as "extern" as I do with functions. I''m not sure if you know what I mean due to the fact that I don''t quite remember the difference between "declare" and "define"!
How do I declare a struct?
Well, the topic says it all. I have a struct implemented as this:
Thomas - www.moelhave.dk
I'm not quite sure what you mean but if your looking for the diffrence between delacreing something and defineing it. Here is the diffrence.
You would not want to use #define with structures.
------------------------------------------------------------
I wrote the best video game ever, then I woke up...
Edited by - Galileo430 on September 29, 2000 5:36:17 AM
//Delcarestruct matrix4_4; // Just told the compiler to expect the//structure martix4_4 later in the file.#define martix4_4(*a, *b) *a + *b //Just told the compiler to//insert the code a + b into//the line wherever it //see's matrix4_4.
You would not want to use #define with structures.
------------------------------------------------------------
I wrote the best video game ever, then I woke up...
Edited by - Galileo430 on September 29, 2000 5:36:17 AM
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Thank you for your reply. It seems that my use of "define" was wrong .. I'll try to explain my problem again...
I have a matrix.cpp with the actual functions and structs. I include this file once, then I have a matrix.h which I wan't to include when I need the funcs and strucs (that's how it's done, right?), in this file all functions are prototyped (that's the word right?) like this:
but to use the struct I need to prototype them too, can I do that like..
or like:
or something completely different?
Edited by - Thoooms on September 29, 2000 5:45:47 AM
Edited by - Thoooms on September 29, 2000 5:46:38 AM
Edited by - Thoooms on September 29, 2000 5:48:05 AM
I have a matrix.cpp with the actual functions and structs. I include this file once, then I have a matrix.h which I wan't to include when I need the funcs and strucs (that's how it's done, right?), in this file all functions are prototyped (that's the word right?) like this:
extern void CoolMatrixStuff(Matrix_4x4 in);
but to use the struct I need to prototype them too, can I do that like..
extern struct Matrix_4x4;
or like:
extern struct Matrix_4x4{float M[4][4];};
or something completely different?
Edited by - Thoooms on September 29, 2000 5:45:47 AM
Edited by - Thoooms on September 29, 2000 5:46:38 AM
Edited by - Thoooms on September 29, 2000 5:48:05 AM
Thomas - www.moelhave.dk
i don''t think you can prototype structs, you have to put the entire struct in the header file (please correct me if i''m wrong)
your matrix.cpp should contain the functions and include matrix.h:
#include "matrix.h"
void CoolMatrixStuff(Matrix_4x4 in)
{
}
the structure definitions and func decl should be in the header:
and just include the header wherever you need the functions. extern is only needed when declaring things like variables.
crazy166
some people think i'm crazy, some people know i am
Edited by - crazy166 on September 29, 2000 8:23:06 AM
Edited by - crazy166 on September 29, 2000 8:23:44 AM
#include "matrix.h"
void CoolMatrixStuff(Matrix_4x4 in)
{
}
the structure definitions and func decl should be in the header:
struct Matrix_4x4{ float m[4][4];};void CoolMatrixStuff(Matrix_4x4 in);//note no extern needed
and just include the header wherever you need the functions. extern is only needed when declaring things like variables.
crazy166
some people think i'm crazy, some people know i am
Edited by - crazy166 on September 29, 2000 8:23:06 AM
Edited by - crazy166 on September 29, 2000 8:23:44 AM
crazy166 is almost right, but he has overseen one thing:
struct Matrix_4x4 {
float M[4][4];
}
declares a variable named Matrix_4x4. And that shouldn''t be done in any header. Use typedef to define the type Matrix_4x4 which can than later be declared as variable like Matrix_4x4 my_mat.
That will define the new variable type Matrix_4x4 in your header file, you may use this type later on in any .c/.cpp source file that has included Mat4x4.h (or however you named it)
-Markus-
struct Matrix_4x4 {
float M[4][4];
}
declares a variable named Matrix_4x4. And that shouldn''t be done in any header. Use typedef to define the type Matrix_4x4 which can than later be declared as variable like Matrix_4x4 my_mat.
//// Mat4x4.h//#ifndef __MAT4X4_H_INCLUDED__#define __MAT4X4_H_INCLUDED__// typedef struct Matrix_4x4 { float M[4][4]; } Matrix_4x4;//Matrix4x4 Mat4x4_Multiply(Matrix4x4 *m1, Matrix4x4 *m2);Matrix4x4 Mat4x4_Add(Matrix4x4 *m1, Matrix4x4 *m2);//#endif __MAT4X4_H_INCLUDED__
That will define the new variable type Matrix_4x4 in your header file, you may use this type later on in any .c/.cpp source file that has included Mat4x4.h (or however you named it)
-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
struct Matrix_4x4 {
float M[4][4];
};
declares a variable named Matrix_4x4. And that shouldn''t be done in any header. Use typedef to define the type Matrix_4x4 which can than later be declared as variable like Matrix_4x4 my_mat.
------------------------------
No this declares a variable:
struct structname variablename;
struct structname {data} variablename;
This declares a type:
typedef struct {data} structname;
struct structname {data};
If you don''t typedef you have to declare a variable like this:
struct structname variablename;
Typedefd:
structname variablename;
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
The Micro$haft BSOD T-Shirt
float M[4][4];
};
declares a variable named Matrix_4x4. And that shouldn''t be done in any header. Use typedef to define the type Matrix_4x4 which can than later be declared as variable like Matrix_4x4 my_mat.
------------------------------
No this declares a variable:
struct structname variablename;
struct structname {data} variablename;
This declares a type:
typedef struct {data} structname;
struct structname {data};
If you don''t typedef you have to declare a variable like this:
struct structname variablename;
Typedefd:
structname variablename;
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Of course, ImmaGNUman.
I''ve always used typedef in my programming style, so I hadn''t thought of the old, normal struct way.
You''re absolutely right Crazy166. Sorry!
(Thought the code posted will still work, just another writing style )
-Markus-
I''ve always used typedef in my programming style, so I hadn''t thought of the old, normal struct way.
You''re absolutely right Crazy166. Sorry!
(Thought the code posted will still work, just another writing style )
-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Thanks a lot for your replies, I''m know pretty sure that I''ll never forget this stuff again, and I can spend time writing juicy gfx code instead of boring MFC progs
Thomas - www.moelhave.dk
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement