|
Can anyone explain me what is the difference in determination value?
double a = 0.0;
double a = .0;
double a = 0.;
|
|
|
|
|
No difference, they all represent the value 0.00, they are just different ways of writing it in source code. You could easily have found this out by writing a small program and stepping through it with your debugger.
|
|
|
|
|
Does exist any document or standard how correct use it forms?
|
|
|
|
|
|
Sorry, what do you mean by 'correct'? All the examples are correct, in that they declare the value as zero.
|
|
|
|
|
Hi,
I have a Base Class Header File as follows,
class MyClass,typedef void (MyClass::*PFN_DO_SOMETHING)(void* pData);
class MyClass{
PFN_DO_SOMETHING m_pfnDoSomething;
void Act(void* pData);
}
void MyClass::Act(void* pData){
m_pfnDoSomething(pData);
}
Needless to say, 'pfnDoSomething' has been initialised elsewere. I boiled the question down to the essentials, the correct CPP syntax for calling a member function from a pointer to it.
I get a Compiler error stating that 'pfnDoSomething' does not resolve to a function call.
What is the correct syntax for calling this function.
regards
Bram van Kampen
modified 2-Jun-16 4:00am.
|
|
|
|
|
The solution:
class MyClass{
typedef void (*MyClass::PFN_DO_SOMETHING)(void* pData);
PFN_DO_SOMETHING m_pfnDoSomething;
void Act(void* pData);
};
void MyClass::Act(void* pData){
m_pfnDoSomething(pData);
}
Your errors:
- The asterisk in the
typedef is at the wrong place. - Place the
typedef inside the class to avoid the forward declaration which would not work here with the correct typedef . - The function member name is
m_pfnDoSomething (not pfnDoSomething ).
Note also that there is no need to use the class prefix with the typedef . You may also use:
typedef void (*PFN_DO_SOMETHING)(void* pData);
|
|
|
|
|
I've always had difficulty with this, but if memory serves, function pointers in classes are required to be declared static .
[edit]
Memory does not serve.
[/edit]
modified 2-Jun-16 3:16am.
|
|
|
|
|
As per Jochen's answer but I would also add a guard against your forgetting to set the pointer checking it's not NULL. The typecast and advance definition is also unnecessary unless you actually need the type for something, the pointer will be checked for match when you attempt to set it with or without the typecast.
void MyClass::Act(void* pData){
if (m_pfnDoSomething) m_pfnDoSomething(pData);
}
Here is a minimalist function ptr .. no need for forward delaration, typedef or even a name of field. All you need is the * dereference before the function ptr name it knows what you are doing from that and really all it needs is what the function looks like so when you try to set it, that it checks for match.
class MyClass{
void(*MyClass::m_pfnDoSomething)(void*);
void MyClass::Act(void* pData){
if (m_pfnDoSomething) m_pfnDoSomething(pData);
}
};
Finally especially since your in a class I would suggest you don't pass in the void* data pointer but look at other options to typecast or marshal the data in a way that is a little safer.
In vino veritas
modified 4-Jun-16 11:36am.
|
|
|
|
|
How to generate XML file dynamically using C on Linux platform?
|
|
|
|
|
The quick and dirty way it is just matter of printf (and the gcc compiler).
e.g.
#include <stdio.h>
int main(int argc, char * argv[])
{
if (argc != 2) return -1;
printf("<html>\n<head></head>\n<body>\n<p>hello %s, welcome!</p></body></html>", argv[1]);
return 0;
}
|
|
|
|
|
|
Which part(s) are you having trouble with: creating a file, writing data to that file, forming XML, etc?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi,
Well, you have to write the Content!
I have no idea of your compiler environment, but, for starters you need to create or select a folder and a File, where the resulting code will be stored. These files would have a 'htm' or 'html' extension. Most environments I know create the Headers and Footers for a blank Page. You have to write the content of the Page in between. You can inspect your work by opening it in Internet Explorer.
Bram van Kampen
|
|
|
|
|
How to determine file offset of each section using RVA in pe file ?
|
|
|
|
|
Quote from Visual Studio, Microsoft Portable Executable and Common Object File Format Specification RVA Relative virtual address. In an image file, the address of an item after it is loaded into memory, with the base address of the image file subtracted from it. The RVA of an item almost always differs from its position within the file on disk (file pointer).
In an object file, an RVA is less meaningful because memory locations are not assigned. In this case, an RVA would be an address within a section (described later in this table), to which a relocation is later applied during linking. For simplicity, a compiler should just set the first RVA in each section to zero.
|
|
|
|
|
I recommend that you read the many books written by Matt Pietreck on the subject. Even books about Win98 or XP will do. They are Classics, but, explain the lot, in your case in particular, how executable files are mapped to memory. I think that this forms part of the foundation every software engineer should have at his finger tips. Matt wrote several books about spelunking in the bowels of the various windows versions. However User Beware! If you are just interested in how your windows version on your computer does things, read, spelunk, and learn! If you start writing software on the basis of what you learn there, BEWARE! It will work, without doubt on Your computer(where you did the Spelunking!) There is absolutely no guarantee that it will work on any other computer, nor, that it will work after the next windows update! Microsoft provides a large API (Application Program Interface), which Microsoft guarantees to support over the various upgrades. Doing things outside this interface, will sooner or later lead to disaster.
Regards,
Bram van Kampen
|
|
|
|
|
We have a big structure with nearly 300 member variable arrays within it. A Partial of the structure is shown below. We have this structure shared in the memory with another application using CreateFileMapping function. So both the application runs in the same machine sharing the memory. The values of the structure keeps on changing continously based on formulas and calcualtions. Now I need to transfer some of the data values that are changed to another application using sockets continously. If I try to transfer the entire structure of size around 900000bytes continously it gives me problem and hangs.
Please provide me step by step methods to get the values of some of the member variables from the entire structure simply without using any loops to some other structure (only changed values) so that I could transfer this comparitively small structure via sockets to another application and do a similar copy method to get the changed data to the same struture TModDB there in the other application.
struct TModDB
{
float IVKK [600];
char FIL [600];
char FDDD [600];
float FCDCP [600];
float FLH [600];
float FEFTH [600];
float FKL [30][600];
float FPRES [600];
float FTEMP [600];
float FHTR [600];
float FXS [30][600];
float FS1S [600];
float FPDER [600];
float FTDER [600];
float FXDER [30][600];
float FS1DER [600];
float FS5DER [600];
float HEHF [200];
float SS2 [1500];
float SMP [30][1500];
float SK1 [1500];
float SK2 [1500];
float SK3 [1500];
float P1 [250];
float P2 [250];
float P3 [250];
float P4 [250];
float P5 [250];
char LOGIC [100];
float MK3 [100];
char CLOGIC [92];
char CSWT [92];
char LOGV [1500];
char SFEFTH [600];
char SFHOLDUP [600];
char SFTEMP [600];
char SHECDER [200];
char SHEHDER [200];
char SCSPEED [92];
char SFPRES [600];
char SFSDER [30][600];
char SGEFDER [300];
float LMHI [750];
float LMLO [750];
char XVA ;
char FRZE;
char GGGO;
.
.
.
.
char MdelCd;
};
|
|
|
|
|
manoharbalu wrote: Please provide me step by step methods to get the values of some of the member variables Not very easy since we have no idea which items you want copied. In essence you need to define your smaller structure and then use memcpy on the elements you want to copy over.
|
|
|
|
|
Please assume that every alternate member variable data in that structure is to be copied.
|
|
|
|
|
OK, assuming that, what is the problem?
|
|
|
|
|
Define your own protocol to be used with the socket communication. Then send a packet when data has been updated by a calculation. The protocol should be able handle the possible amount of data that is updated by your calculations.
A possible protocol structure may be:
typedef struct
{
int updateType; int firstNdx; int lastNdx; int dataLen; char data[1]; } MyUpdateProtocol;
The updateType may be an enum instead of an <code> int:
enum MyDataMembers
{
IVKK,
FIL,
FDDD,
FCDCP,
};
To create a protocol block calculate the amount of data bytes, allocate memory, cast it, fill it, and send it. Example:
int firstNdx = 0;
int lastNdx = 10;
int dataSize = ((lastNdx - firstNdx) + 1) * sizeof(float);
char *buf = new char[dataSize + sizeof(MyUpdateProtocol) - 1];
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
pProto->updateType = IVKK;
pProto->firstNdx = firstNdx;
pProto->lastNdx = lastNdx;
pProto->dataLen = dataSize;
memcpy(pProto->data, &pModDB->IVKK[firstNdx], dataSize);
sendData(buf, dataSize + sizeof(MyUpdateProtocol) - 1);
delete [] buf;
On the receiving side copy the data according to the protocol header fields:
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
void *dest = NULL;
switch (pProto->updateType)
{
case IVKK : dest = &pModDb->IVKK[pProto->firstNdx]; break;
case FIL : dest = &pModDb->FIL[pProto->firstNdx]; break;
}
memcpy(dest, pProto->data, pProto->dataLen);
|
|
|
|
|
EDIT: LOL hadn't read Jochen's response who did it same way but with some nice protocol sizing. That is pretty nice makes the case statements on the copy enumerate easier. Anyhow you get the idea it isn't a hard task. I will leave the code so you can see what his protocol sizing is simplifying. Did you ever get the network transfer sorted?
Like the people said whats the problem?
You can just do as basic as memcpy I just grabbed your struct and made a zeroed instance and did it to show you.
struct TModDB MyModDB = { 0 };
float DupFXS[30][60];
memcpy(DupFXS, MyModDB.FXS, sizeof(DupFXS));
Really as a commercial thing I would make an enumerator and a single function to copy whatever field I pass the enumerate of or if I can use C++ make it a class or object.
The C enumerate option looks something like follows, your job is to provide a buffer and it's size to the function for the field you are copying
enum DBENUM {
DE_IVKK = 0,
DE_FIL,
DE_FDDD,
DE_FCDCP,
DE_FLH,
};
BOOL DBCopyFunction (enun DBNUM whatToCopy, struct TModDB* TheDB, void* Buf, long SizeOfBuf){
BOOL success = FALSE;
if (TheDb){
switch(whatToCopy){
case DE_IVKK: {
if (sizeof(TheDB->IVKK) <= SizeofBuf) {
memcpy(Buf, TheDB->IVKK, sizeof(TheDB->IVKK));
success = TRUE;
}
}
break;
case DE_FIL: {
if (sizeof(TheDB->FIL) <= SizeofBuf) {
memcpy(Buf, TheDB->FIL, sizeof(TheDB->FIL));
success = TRUE;
}
}
break;
}
}
return (success);
}
There isn't anything complicated that it's just a large complex structure.
In vino veritas
modified 31-May-16 10:28am.
|
|
|
|
|
Thanks a lot for the suggestions.
Let me brief the architecture for your kind understanding
We have 3 applications involved.
1. Model (Runs along with the server and shares the data with Server through Shared memory. Changes the data through formulas and calculations continuously)
2. Server (Updates the data in the shared memory that is changed by the user for recalculation. Gets/Puts the data in shared memory and shares data with model. Also updates client with the updated data from model. Receives user changes from the client.
3. Client (Has number of GUI windows to show the values and receives values from user.)
The Server and the model runs locally and communicates using shared memory. The Client can run either locally or remotely within the network and the communication is using TCP/IP Sockets
I have 2 problems here.
Problem 1:
We dont have hold with the model code. So I cannot detect the value changes from the model.
But both the model and the Server shares the same structure what I have mentioned previously.
So, Is it possible to detect the value changes through shared memory from the Server side?
Problem 2:
As an example if I assume that every alternate member variable array(entire array) is changing, then I have to send 'n' number of times the data through the socket every cycle, where n is the number of member variable arrays in the structure. My concern is the load or performance problem that I had already faced while splitting the data as packets for sending every cycle. I am afraid if the same problem may occur if I send it 'n' number of times.
Please help me and correct me if I am wrong.
|
|
|
|
|
Hi,
You try to detect whether an update has taken place from a remote station.
I take it that you are writing an Application where Clients access the database Direct.
You have two lines of defence here. the function 'stat' will give you the last modify time. If it has not changed since the last time you read it, or wrote to it, your private copy items are still in date.
What to do Next, if the File Stamp has changed. In any case, we need to reload the data, if it affects the records we are dealing with. A Simple check sum will do!
Regards,
Bram
Bram van Kampen
|
|
|
|