|
Hi
There is much confusion, in particular amongst novices, about Pointers, References snd Values when used as arguments.
Using a Value is clear, a copy of the value gets placed on the stack. You can do what you want with it, it will be lost when the stack is cut down when you return from the procedure.
A pointer is also clear, You're passing on the address of some data. That data resides elsewhere, but you're given the access to the original. so Changing the data through the pointer affects the original.
The problem here is that the Pointer may not point at valid memory. This is a condition that can only be checked at runtime. There is no way the compiler can use to check the validity of a pointer at Compile Time.
When you use a Reference, you will get passed the address of the variable to your procedure, and the generated code is identical to passing a pointer. The difference is, that unlike passing pointers, the language syntax and semantics force you to enter the correct variable name.
Hope this helps.
Bram van Kampen
|
|
|
|
|
Hello guys,
I'm trying to build a simple lexical analyzer with Parser Generator 2. I wrote a Lex and a Yacc file and built a *.c and a *.h file with them. As I tried to compile this files I got strange linker errors:
error LNK2019: unresolved external symbol _yywclex referenced in function _yywgettoken
error LNK2019: unresolved external symbol _yywcparse referenced in function _main
fatal error LNK1120: 2 unresolved externals
What can I do against this errors, or do I have to use another compiler?
Thanks and best wishes.
|
|
|
|
|
Hi,
Check if your functions are having same data type for the arguments in header file and c file
Also see if you are having those functions definitions with declaration in header file or forward declaration in C file.
Thanks,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
All the function definitions are in the main file defined with prototypes, so I don't think it's something to do with them.
|
|
|
|
|
You make sure you have included all the headers you needed in c file and any libraries if needed.
Also, all the files you have created are added to your project.
And check if the path of included headers are correct.
Thanks,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
I don't get any errors about libraries or headers that aren't found. So I think the pathes are correct.
|
|
|
|
|
Hi
Without being funny, you have to do something all of us do most of the time, It's called debugging. You wrote the code, You know what's in it.
And you Need to know what's in it!!
As a Hint, it seems your linker missed a lib.
Find out which one, and write:
#pragma comment(lib,"MyMissing.Lib");
Bram van Kampen
|
|
|
|
|
I already tried debugging the project, but I just got the message that something is wrong with the linker.
|
|
|
|
|
Well,
The functions yywclex(??) and yywcparse(??) have been declared, are being used in the stated modules, but have not been defined. That's why the linker cannot find them. Do a text search for these functions. If you cannot find a definition for them there may be something wrong with your generator. an other possibility is that you were supposed to write those yourself. Check the documentation for YACC. Thirdly, Is there a bug in your rules script, which results in YACC not generating those functions.
It is unlikely that there is something wrong with your linker. Also, because the code is in 'C', errors in type declarations may cause a run time issue, but will not be found by the linker. The functions:
'int f(int)' and 'int f(char,char) are both mangled to '_f' by the compiler.
Hope this helps
Bram van Kampen
|
|
|
|
|
I solved this problem by rebuilding all the library files which are included.
Now there's just one erroe left, but I don't thnk that this one has something to do with VC++, but with the lexer and parser generator I'm using.
|
|
|
|
|
Well, at least you're getting a handle on things. Gives a good feeling though, doesn't it.
Regards,
Bram van Kampen
|
|
|
|
|
I have a structure:
typedef struct{
unsigned short Id : 8;
unsigned short Name: 8;
unsigned short Length: 11;
unsigned short Value: 5;
} MyStruct;
I also have an array of bytes (unsigned char):
I want to stick that structure into the first four bytes in the array.
Array[0] = MyStruct->Id;
Array[1] = MyStruct->Name;
...then what?
How can I divide the last two values and put them into the [2] and [3] position in the byte array?
|
|
|
|
|
|
Please note sizes are identical. Methods
(1) quick & dirty: copy memory
MyStruct m;
unsigned char a[4];
memcpy(a, &m, sizeof(a));
(2) perhaps more elegant: use union
typedef union
{
MyStruct m;
unsigned char a[4];
}MyUnion;
MyUnion mu;
unsigned char array[4];
for (i=0; i<4; i++)
{
array[i]=mu.a[i];
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It looks like the memcpy might work. I didn't really want to go the route of using a Union.
I was actually looking for a method to do this using bit shifting.
Something like...
unsigned char NewChar = MyStruct->Length << 8;
which would put the 8 leftmost bits in Length into the NewChar, which you could put into Array[2];
but then, how do I get the other three bits from Length and merge them with the 5 bits from MyStruct->Value?
I kind of know what I want to do it, but I don't know exactly how, what commands to use or what I'm doing.
|
|
|
|
|
Just for the academy (since memcpy is more concise and probably faster).
MyStruct m;
unsigned char a[4];
a[2] = (unsigned char) m.Length;
a[3] = (m.Length >> 8) | (m.Value << 3);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Cool.
That's what I was looking for originally. But the memcpy works.
THANKS!
|
|
|
|
|
|
"how to set background color ?"
Hi ,
U can handle WM_CTLCOLORDLG to change the background color of the dialog.
In the link u have given, the code is not returning the handle to the new bursh u want to set for the dialog. See what msdn says
"OnCtlColor must return a handle to the brush that is to be used for painting the control background".
In the code u r returning the default brush handle. so that may the problem of not changineg the background color.
and change your code like this
<br />
if(nCtlColor == CTLCOLOR_DLG)<br />
{<br />
hbr = CreateSolidBrush(RGB(2,22,222));<br />
}<br />
thanks
Nitheesh
modified on Friday, April 11, 2008 10:58 AM
|
|
|
|
|
Dear Nitheesh,
I am still not able to change the background color after I tried the code below. As I'm a beginner of c++, would you please point out the deficit or improper use of code. Thank you very much!
HBRUSH CMyAppView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CScrollView::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG)
{
hbr = CreateSolidBrush(RGB(2,22,222));
}
return hbr;
}
Cheers,
john
|
|
|
|
|
You can use ofWM_CTL* for change color of buttons,dialog,static control and....
|
|
|
|
|
Hi All,
I am enumerating the network adapters by using the GetAdaptersInfo() API. But, I am not able to distinguish between the ethernet and wireless network as both the adapters are having the type as MIB_IF_TYPE_ETHERNET. Does anyone have an idea?
Thank you,
AJ
|
|
|
|
|
Looking at the documentation on MSDN GetAdaptersInfo( ) doesn't return that much detail and has been superseded by GetAdaptersAddresses[^] as of Windows XP, however even that only looks like it will differentiate between wired and wireless on Vista and not XP.
Gavin Taylor
|
|
|
|
|
Hi all,
I want to change default blue color of title bar for my SDI window.
I tried painting title bar area through OnNcPaint() but Icon, Caption,Buttons gets disappear, on mouse over buttons appear.
help me with some solution
thanks
|
|
|
|
|
SetSysColor<br />
GetSysColor
Hope it helps.
|
|
|
|