|
What do you need exactly?
|
|
|
|
|
some realtime example do demonstrate the use of union.
|
|
|
|
|
For see some detaily of union I suggest see Other Data Types section on the www.cplusplus.com.;)
|
|
|
|
|
chandu004 wrote: some realtime example do demonstrate the use of union.
from wdm.h (a driver include file):
typedef struct _PCI_COMMON_HEADER {
USHORT VendorID;
USHORT DeviceID;
USHORT Command;
USHORT Status;
UCHAR RevisionID;
UCHAR ProgIf;
UCHAR SubClass;
UCHAR BaseClass;
UCHAR CacheLineSize;
UCHAR LatencyTimer;
UCHAR HeaderType;
UCHAR BIST;
union {
struct _PCI_HEADER_TYPE_0 {
ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
ULONG CIS;
USHORT SubVendorID;
USHORT SubSystemID;
ULONG ROMBaseAddress;
UCHAR CapabilitiesPtr;
UCHAR Reserved1[3];
ULONG Reserved2;
UCHAR InterruptLine;
UCHAR InterruptPin;
UCHAR MinimumGrant;
UCHAR MaximumLatency;
} type0;
struct _PCI_HEADER_TYPE_1 {
ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
UCHAR PrimaryBus;
UCHAR SecondaryBus;
UCHAR SubordinateBus;
UCHAR SecondaryLatency;
UCHAR IOBase;
UCHAR IOLimit;
USHORT SecondaryStatus;
USHORT MemoryBase;
USHORT MemoryLimit;
USHORT PrefetchBase;
USHORT PrefetchLimit;
ULONG PrefetchBaseUpper32;
ULONG PrefetchLimitUpper32;
USHORT IOBaseUpper16;
USHORT IOLimitUpper16;
UCHAR CapabilitiesPtr;
UCHAR Reserved1[3];
ULONG ROMBaseAddress;
UCHAR InterruptLine;
UCHAR InterruptPin;
USHORT BridgeControl;
} type1;
struct _PCI_HEADER_TYPE_2 {
ULONG SocketRegistersBaseAddress;
UCHAR CapabilitiesPtr;
UCHAR Reserved;
USHORT SecondaryStatus;
UCHAR PrimaryBus;
UCHAR SecondaryBus;
UCHAR SubordinateBus;
UCHAR SecondaryLatency;
struct {
ULONG Base;
ULONG Limit;
} Range[PCI_TYPE2_ADDRESSES-1];
UCHAR InterruptLine;
UCHAR InterruptPin;
USHORT BridgeControl;
} type2;
} u;
} PCI_COMMON_HEADER, *PPCI_COMMON_HEADER;
Depending on the value in HeaderType, one of the three unions (type0, type1 or type2) is the "correct" one to be used.
|
|
|
|
|
i used to use it when programming microcontrolers in my electronic classes... i had some devices sharing the same memory address with different registers, for which the union is the exact logical representation then...
|
|
|
|
|
|
A structure is a collection of items of different types; and each data item will have its own memory location. Where as only one item within the union can be used at any time, because the memory allocated for each item inside the union is in a shared memory location i.e., only one memory location will be shared by the data items of union.
Size of union will be the size of the biggest variable.
For eg
#include "stdafx.h"
struct s
{
int i;
char ch;
float f;
};
union u
{
int i;
char ch;
float f;
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
s s1;
u u1;
printf("%d %d",sizeof(s1),sizeof(u1));
return 0;
}
than result is 12 and 4 .I think now it is clear for u.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
What is the difference between 'constant pointer' and 'pointer to a constant'? with example.
|
|
|
|
|
Constant pointer can never be advanced.
Pointer to a constant points to a constant object. The target value can never be changed.
Maxwell Chen
|
|
|
|
|
|
Dear All.
in one multi threaded project, we have 15 threads.
We want to restrict any thread to not write data into the memory space of other threads.
How we can do this ?
Is there any document about thread memory space available.
Regards
Monhi
|
|
|
|
|
Gut Mikh Tappe wrote: thread memory space
Hmm, under Windows the only Thread specific Memory Space is Thread Local Storage (TLS) which is already protected and can't be over written by other threads without some knowledge and some assembly code. Each thread has it's own stack so you don't need to worry about anything stack based. Heap memory, allocated with new , is shared and this you do need to protect. There's no single or simple way to do this, you need to manually keep track of all objects ( I hope your code is OO ) shared between threads. Each of these objects needs protecting using relevant Synchronisation Objects, sometimes called Synchronisation Primitives. Critical Sections, Mutexes, Events, Semaphores and Completion Ports. There is an extensive Synchronisation section of the Win32 API which you can use to create, lock, unlock and free these objects which are implemented by the Windows Kernel. If you use a framework like MFC some or all of these objects may be provided with easy to use wrappers along with useful classes like stack based Mutex Locks. I hope this is enough to get you started.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Dear Matthew
Do you know any function to lock a space which is allocated by new operator.
Regards
|
|
|
|
|
preliminarily,
did you try to use some global flags as the semaphores?
this simple technique worked for me for solving very complex thread problems.
just try it out and see.
|
|
|
|
|
I am writing a plugin which get text from WORD after quitting WORD. But I do not know how to catch Quit event of WORD from my plug-in function.
Thanks
Phan Minh Duy.
|
|
|
|
|
hi,
i want to transfer to login page after 5 minutes of login
Md.Rafiuddin
Sr. Software Engineer,
IndusBusiness Systems,
Hyderabad
|
|
|
|
|
mmm... Anyone here is/knows a medium? Maybe then can someone know what is this quesion about.
"after 5 mins"
What about a Timer?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
What "login page?" Please explain, in detail, what are you after.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Rafiuddinmd wrote: i want to transfer to login page after 5 minutes of login
Go on then!
Taking a guess at your question... (As a SENIOR software engineer, you should be able to actually phrase a question....)
Set a 5 minute countdown on the screen saver, and tick the box saying "On resume password protect". The wording is accurate for english windows XP, but I'm sure the idea is the same in Vista etc.
Iain.
|
|
|
|
|
Hi,
I have a little problem in class declaration.
It is easy to understand, and to solve too, I believe: my class are declared in 2 separated header files:
A.h =>
#pragma once
#include "B.h"
class A
{
protected:
B* m_Bparam;
...
}<=
B.h =>
#pragma once
class B
{
protected:
A* m_Aparam
...
}<=
I imagine you can see the problem. When starting to compile A.h file, it will read B.h where a A type parameter is declared, but the compiler doesn't know the class A yet.
Is there any keyword to help solve this solution? I think I can find a workaround by using interfaces, but I imagine there is an easier way to do so, and get a clean program.
Thank you in advance,
Fred
|
|
|
|
|
predeclare them, this will only work because you are not actually using them just declaring a pointer.
A.h =>
#pragma once
class B;
class A
{
protected:
B* m_Bparam;
...
}<=
B.h =>
#pragma once
class A;
class B
{
protected:
A* m_Aparam
...
}<=
|
|
|
|
|
Roger already gave you the solution, but if you want to find more info on the subject, you can google for "forward declaration" (that's how it is called).
|
|
|
|
|
Thank you very much Roger and Cedric!
Have a nice day !
|
|
|
|
|
Hi everyone,
How to add a page in the mouse of the control panel ?
Thanks!
Nike
|
|
|
|
|