|
|
My advice on ellipsis - Don't use them, there're crap. My gripe is that it is impossible to create a type safe function that uses ellipsis.
Steve
|
|
|
|
|
I have a minor problem. I have a bit field (see below). I also have a few places where I deal
with the different parts of it. I've recently had to change the size of one of the fields, and
have to find all the places I've hardwired the old size.
If this was an array of BOOL / bools, I could use the sizeof operator. Is there any way of
deriving the size of the fields simply from the code?
I know there are various brute force approaches, use NUM_LAYERS_OVERLAYS (etc) everywhere,
change to struct containing a load of BOOLs, or BYTES, but the purist in me is intrigued
as to whether there is a more elegant solution....
Suggestions please?
Iain.
union _Layers_
{
DWORD dwAll;
struct _Parts_
{
DWORD dwImage : 1;
DWORD dwMesh : 1;
DWORD dwShapeMatch : 1;
DWORD dwComments : NUM_LAYERS_COMMENTS;
DWORD dwSelections : NUM_LAYERS_SELECTIONS;
DWORD dwOverlay : NUM_LAYERS_OVERLAYS;
} Parts;
_Layers_ ()
{
dwAll = -1;
}
};
|
|
|
|
|
Iain Clarke wrote: I've recently had to change the size of one of the fields, and
have to find all the places I've hardwired the old size.
What do you mean by this? I use bitfields all of the time and I change them all of the time. I can not think of a reason to 'hardwire' the old size except in the structure definition.
When you use parts, you reference by variable name. When you use the whole word you use dwAll. I guess you could make changes to dwAll by using bit operations, but that could have been avoided by using your structure.
|
|
|
|
|
Bob Flynn wrote: When you use parts, you reference by variable name
Don't worry, I do know that. This structure hold bits toggling whether some display features are turned on or off in my software.
I also have a dialog box, which shows a column of checkboxes on one side, and the "type" of bit on the other. When I changed the number of bits for each parts, I needed to change the dialog box. I was thinking of a way for the dialog box to automatically recongnise the changes if I made more in 2 years time.
I have since thought of a solution (in the bath, so I haven't tried it yet).
_Layer_ L.
int nBits;
L.dwAll = -1;
nBits = L.Parts.dwComments;
nBits++;
nBits = log (nBits, 2);
I'm sure I haven't got the syntax of the log command right, but the principal is there.
This was more of a puzzle than a real problem, as I did have alternative (but less pretty) ways of solving the problem.
Thanks,
Iain.
|
|
|
|
|
OK, I see what you are going for.
I think what you have will work just fine. Perhaps instead of a log2 function you may find that simply finding the non zero bit by counting will be a faster operation.
i = 0;<br />
while ((i < 32) && ((src & 0x80000000) == 0))<br />
{<br />
src = src << 1;<br />
++i;<br />
}
This will tell you how many leading zeros are in your word, therefore providing the location of the first non-zero value.
|
|
|
|
|
I am trying to push a variable of type bobject into a vector, i get an assertion error when i try to push it. Does anybody know what the problem could be?
|
|
|
|
|
Show your code, especially how you declared your vector (be sure to check the 'Ignore HTML tags in the message' checkbox located below the posting edit box on the CP posting page), the line where you call push_back (or push_front) and then it might help if you also posted the lines that generated the actual assertion (will contaion the text ASSERT or VERIFY or some variation there of) that your debugger will jump to when you tell it to debug your program after the assertion happens.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
The code which pushes the vector
bobject o=read_Obj(argv[i]);
o.active=1; //Active
o.picked=0;//Not picked
o.path=argv[i]; //save object path
---------------->store_normal(o);
glLoadIdentity ();
glGetFloatv(GL_MODELVIEW_MATRIX,o.m);
//initialize all variables
cout<<"in"<<endl;
----------------->ob.MyObjects.push_back(o);
the store_normal code is
void store_normal(bobject o)
{
for(int i =0;i<o.faces.size();i++)
{
//caculate the normal of the vertices
GLfloat x;
GLfloat y;
GLfloat z;
//vertex1 - vertex2
float a1= o.faces[i].second.x- o.faces[i].first.x;
float a2= o.faces[i].second.y- o.faces[i].first.y;
float a3= o.faces[i].second.z- o.faces[i].first.z;
//vertex2 - vertex3
float b1= o.faces[i].third.x-o.faces[i].first.x;
float b2= o.faces[i].third.y-o.faces[i].first.y;
float b3= o.faces[i].third.z-o.faces[i].first.z;
//calculate x y,and z cordinates for normal using cross product
x=(a3*b2)-(a2*b3);
y=(a1*b3)-(a3*b1);
z=(a2*b1)-(a1*b2);
//1st normal
o.vert[o.faces[i].v1].norm.x =o.vert[o.faces[i].v1].norm.x+x;
o.vert[o.faces[i].v1].norm.y =o.vert[o.faces[i].v1].norm.y+y;
o.vert[o.faces[i].v1].norm.z =o.vert[o.faces[i].v1].norm.z+z;
//2nd normal
o.vert[o.faces[i].v2].norm.x =o.vert[o.faces[i].v2].norm.x+x;
o.vert[o.faces[i].v2].norm.y =o.vert[o.faces[i].v2].norm.y+y;
o.vert[o.faces[i].v2].norm.z =o.vert[o.faces[i].v2].norm.z+z;
//3rd normal
o.vert[o.faces[i].v3].norm.x =o.vert[o.faces[i].v3].norm.x+x;
o.vert[o.faces[i].v3].norm.y =o.vert[o.faces[i].v3].norm.y+y;
o.vert[o.faces[i].v3].norm.z =o.vert[o.faces[i].v3].norm.z+z;
}
}
this assertion error occurs when i include store_normal(o);
|
|
|
|
|
You have still not supplied the crucial piece of information, what is the exact assertion? Just saying "an assertion happened" means nothing, it could be anything.
Learn to use the tools you have in front of you. Start the debugger, step through and into your code. Watch the values of all your variables, and when you hit an assertion look at the code and all the variables referenced in that code. At least one of the variables will have an invalid value. Figure out which one it is, and then use the call stack to backtrace to where that invalid value was set.
It can take a little bit of detective work, but you can do it. I can't do it with the information you have supplied so far.
Good Luck!
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
in visual c++6 ,how can i write /in/ or read /from/ any port like LPT?
|
|
|
|
|
|
i've a project build by C++ and include header from borland and other.
how can i open this project into project on .NET in C++?????
Militiaware
Faris Madi
|
|
|
|
|
create an empty project and import the sources in it.
note that you'll have some incompatibilities if the sources were not pure standard C++
|
|
|
|
|
I want to call a commandline exe, which puts some string into the console. I want to redirect this into a string or into a file.
I tried CreateProcess with pipeing(>) the output to a file, but for some reason its not working...
It would be helpful if i could get some info on different ways achiving the above.
|
|
|
|
|
|
Ola.
I have a little wtf here, which seems unsolvable by googling (I tried and did not find any clues):
I have an ostringstream strbuf.
I do the following:
strbuf.width(14);
strbuf << "????/????";
After that, strbuf.str() is called and written to an output-file.
If I put "????/????" into strbuf, "??????" is written to the file.
If I use "????//????" instead, "??/????" is written out.
So, there may be a special meaning to "?" or "/" or both when used in a ostringstream.
Can anyone enlighten me on this one?
Note: Yes, its a "forward slash" not a "backslash", exactly as used here.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
It is called a Trigraph, a sequence of three characters that starts with two question marks that the compiler uses to generate punctuation marks. Its a C leftover from the days of 7 bit ASCII.
This is what is happening:
"????/????" - contains trigraph '??/' which translate to '\'
"??\????" - contains escape sequence '\?' which translate to a literal question mark
"??????" - final result
Lookup Trigraphs in MSDN.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
-- modified at 10:48 Monday 20th March, 2006
|
|
|
|
|
i have a doubt :
are you sure trigraphs also work within strings ?
|
|
|
|
|
Read about trigraphs in MSDN. It says the compiler translates them in the first translation phase, before it does anything else. So yes, trigraphs are translated everywhere in the source code, string literals included.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
As I mailed you before:
Many thanks. I knew about trigraphs, but it didn't occur to me that they were causing these problems.
Cheers,
Sebastian
--
But I just may be the lunatic
you are looking for
-- Billy Joel --
|
|
|
|
|
I am trying to figure out how to instantiate a class that contains another class. For example, if I have a class called TopClass that contains a class called InClass :
class TopClass{
TopClass();
TopClass(int xIn);
InClass x;
}
class InClass{
InClass();
InClass(int xIn);
int xIn;
}
Even when I use non-default constructor in TopClass and called the equivalent one in InClass, it seems that the default construct in InClass has already been called to create a vanilla object. Is there any way I can automatically transfer the input variables to InClass when the non-default constructor is created? Or should I simply use pointers and initialize the pointer to a new InClass object the non-default constructor is called in TopClass?
Thanks in advance for any info.
Kiernan
|
|
|
|
|
I'm not certain I understand correctly but will this not work ?
TopClass::TopClass( int xIn ) : x( xIn )
{
}
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
<naughty>I see you skipped the chapter on initialisation lists when you were learning C++</naughty>.
Well to be honest, it IS an obscure topic and quite easy to miss when you're learning C++. So I'll let you off... THIS time.
Anyway, the answer is to use an initialisation list.
class TopClass()
{
TopClass(int xIn)
: x(xIn)
{
}
InClass x;
};
-- modified at 10:24 Monday 20th March, 2006
|
|
|
|
|
Thank you for the help. I guess I did skip that chapter. I am learning C++ after having learned Java, so this is a subtlety that escaped my attention since this problem doesn't really occure in Java due to its lack of definitions.
You answer does however bring me to another question. Isn't that the same syntax used used for passing variables to an inherited version of a function? Did I miss the big picture, whereby that syntax basically allows me to pass values to any other valid function?
Regards
Kiernan
|
|
|
|