|
|
Thanks I saw that but could not find any sample code I could compile there
|
|
|
|
|
Maybe you need to write it.
|
|
|
|
|
Maybe post the compilation errors that you are seeing along with the pertinent code.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Hi,
I am working LDPC encoding and decoding for hardware implementation.Through Vivado HLS, I need to transform a parity-check matrix H (that only consists of ones and zeros) from a non-standard to a standard form through C/C++ programming language. Here below you may find samples of non-standard parity check matrices in which Gauss-Jordan elimination (over GF(2)) can be applied.
Initially, i am trying encoding part via C/C++ programming logic. please help me if you do have any idea about LDPC. I would need a method that works out with matrices of any dimension.
this is, express it as
Hsys = [I| P]
This is my H matrix
H=[1 1 0 0 1 0
1 0 0 1 0 1
1 1 1 0 0 1];
Expected Systematic H matrix
Hsys=[1 0 0 1 0 1
0 1 0 1 1 1
0 0 1 0 1 1];
int main()
{
int i,j;
int message;
int H_Matrix[3][6]={{1,1,0,0,1,0},{1,0,0,1,0,1},{1,1,1,0,0,1}};
int temp[3][6]={0};
for(j=0;j<6;j++)
{
temp[1][j]=(H_Matrix[1][j]^H_Matrix[0][j]);
H_Matrix[1][j] = temp[1][j];
temp[2][j]=(H_Matrix[2][j]^H_Matrix[0][j]);
H_Matrix[2][j] = temp[2][j];
temp[0][j]=(H_Matrix[0][j]^H_Matrix[1][j]);
H_Matrix[0][j] = temp[0][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<6;j++)
{
printf("%d\t ",H_Matrix[i][j]);
}
printf("\n");
}
}
|
|
|
|
|
We have a MFC application with a structure that constitutes int, float and char array members. We have declared a global pointer to this struture. This application creates a shared memory using createfilemapping function and assigns the shared memory to this global variable using mapviewfile function.
The same structure is used in a console application1 which is used for doing certain calculations. This console application shares the memory created by the MFC application using openfilemapping and mapviewfile functions.
I want to create another console application2 in which the dimension of the array members of the struture to be modified. If I run the MFC application based on the selection 1 dynamically, it should create the shared memory for console application1. Similarly for selection 2 dynamically, the MFC application has to create shared memory for console application2.
Please suggest me how to do it dynamically when I run the MFC application
Note: When the MFC application is run, it invokes the console application after creating the shared memory. It invokes one console application during its each run based on the user selection.
|
|
|
|
|
You could declare the second structure in the same global space using a union . That way your global structure does not change for the existing application.
|
|
|
|
|
To make my question more specific
Is it possible to dynamically create a single global pointer to 2 different structures based on the selection, one at a time.
For Example:
If pt is the pointer and struct1 and struct2 are the 2 different structures.
if x = 0 then pt refers struct1 else pt refers struct2
Here Pt will be used throughout my application lot many times and places and I dont want to use 2 different pointers.
If it is possible, Please provide me the steps of how to do it. Or please suggest some ways to meet my requirement
modified 15-Jun-17 2:36am.
|
|
|
|
|
Yes it is possible but now you need another global variable to tell which structure it points to. Better to have some flag in the structure, preferably the first item, which tells the rest of the code which one it is. But really using global ob jects/pointers in this way is not good design.
|
|
|
|
|
If I am going to have a single pointer which will dynamically point to any of the 2 structures based on the user selection, then what should be pointer type defined...struct1 or struct2 or void
I have to define the pointer type while I code and point it to any of the strutures dynamically based on the user selection which is mostly one time. After the selection is done, the pointer will point to the selected structure throughout the application run.
|
|
|
|
|
It does not matter, the methods that use the pointer need to cast it to the appropriate type. That's why I suggested using a union as both structures then occupy the same area of memory.
|
|
|
|
|
Can you please give me a small example of declaring the second struture in the same global space using union.
Let me provide an example of the 2 structures that I use in my application
struct test1
{
int x[3000];
float y[2000];
char z[3000];
int a1[3000];
float a2[2000];
char b1[3000];
float c12[5000]; This member is not in test2
.
.
.
};
struct test2
{
int x[4000]; //Same member as in test1 with size increased
float y[1000]; //Same member as in test1 with size decreased
char z[5000]; //Same member as in test1 with size increased
int a1[2500]; //Same member as in test1 with size decreased
float a2[1000];//Same member as in test1 with size decreased
char b1[3000];//Same member as in test1
float abc[5000]; //Newly added in this structure only
.
.
.
};
|
|
|
|
|
|
Seriously it's trivial .. 6 lines of code as combined struct under your other 2 definitions
struct combined_test {
union {
struct test1 test1;
struct test2 test2;
};
}; Read the link he gave you or look up unionized structures
So that is an anonymous union.. AKA struct test1 and test2 occupy the same space no extra name needed.
So if you create a combined struct
struct combined_test lets_use_it;
lets_use_it.test1.z[100] = 10;
lets_use_it.test2.z[100] = 10;
lets_use_it.test1.c12[23] = 10; Where it fills in will respect the position in memory layout of test1.z[100] vs test2.z[100]
Now for your pointer it behaves like a pointer to both structs .. again it's UNIONIZED
struct combined_test* p = (struct combined_test*) malloc(sizeof(struct combined_test));
p->test2.z[100] = 32;
p->test1.z[100] = 55; No rocket science to it and make a sample and debug it if you need to check things.
In vino veritas
modified 15-Jun-17 14:23pm.
|
|
|
|
|
Thanks a lot. You have answered and explained what I had asked for. But I have a few hurdles to implement it.
I already have created the MFC application with a single structure defined in it. The global variable pointer for this structure struct1 is created and used through out the application.
As I had already said this MFC application invokes a console application at a time based on the user selection. There are many nearly some 1000 console applications which already are working. The MFC application creates a shared memory using CreateFileMapping and assigns the structure struct1 pointer to MapViewOfFile. The console application shares the same memory using the same struct1. So the same pointer name is used in both the MFC and all the console applications at many places.
Now my requirement is I have to increase the size and add some of the members in the struct1 to create struct2 for some of the console applications. So Now there will be some console applications that have struct1 and others have struct2. But the MFC application is a common application which invokes any particular console applications based on the selection. But there will be one mfc application and console application running at a time and sharing the memory. So If the MFC application invokes console application of type1 it should create a memory for struct1 and it creates memory for struct2 for console application of type2. The MFC application knows the type of console application at runtime and the pointer to be changed to point to either struct1 or struct2. And the pointer is already used in many many places in various console applications.
Is there a way in the mfc application to redefine the global pointer at runtime to make it point to struct1 or struct2 based on the console application type.
Eg: test->a[1000] = 23; //This usage code cannot be changed since used in many places
Note: Only common member variables are used in the MFC application. Hence the above line in the example will work for struct1 as well as for struct2 as both contains the member variable 'a' of the same type
|
|
|
|
|
First let me say you are making a mountain out of a molehill ... "test->" is a dead easy string to pick off with a text auto-replace on. Would take me about 30sec to do on code throughout the project.
You could also do what a good programmer would do and get rid of the stupid global pointer and pass it into the functions on the local interface. You can keep it as test on the local interface but pass in lets_use_it.test1. You make your code better, safer and it is simply extending a few local interfaces. That is what I would actually do .. globals are evil
The question to ask yourself is why are you using the global pointer rather than having a pointer parameter on the functions that use the global?
That all said you could keep the pointer "as is" if you want by typecasting but it is frowned on
struct test1* test = lets_use_it.test1;
In vino veritas
modified 16-Jun-17 10:22am.
|
|
|
|
|
We have a console application in VS2008 in which we have defined a global variable for a structure. The members of the variable are used throughout the application in various functions.
Recently we have taken some of the functions out of the application to create a separate library and have included the library and the header file in the console application.
Now When I build the application and run it, the output and behavior of the whole application is correct and same as before. But when i try to set breakpoints and debug some of the functions in the console application to watch the values in the watch window, the structure variable shows empty in the value column. The global variable for the structure is also used in the library.
Please suggest a solution to view the values in the watch window
modified 12-Jun-17 7:41am.
|
|
|
|
|
Check the project settings and ensure that both the application and library are built in Debug mode.
|
|
|
|
|
Problem solved. One of the lib was in release mode. got it fixed. Thanks
modified 13-Jun-17 3:38am.
|
|
|
|
|
That should work and does on VS2015 and VS2107 so if it doesn't work on VS2008 it's a very old bug.
You can however easily hack around it, just make a local variable struct and copy the global struct to the local ... the watch window can't get that wrong and it's one single line of code
Other alternative is to try the later compilers, they are free and easy to download and try.
In vino veritas
modified 13-Jun-17 3:04am.
|
|
|
|
|
Hey all,
When you save a webpage, eg from firefox "Web page, complete", it saves an html file and a folder containing its resources. No problem. But the tricky bit is, you move/copy/delete the html file the resource folder does the same.
How do they do that!?? I'm guessing there is some shell extension, but the only thing close I find in MSDN is ICopyHook, which seems more like a proceed/abort confirmation.
Thoughts?
(and dare I ask...) Examples?
|
|
|
|
|
It is a Windows shell feature called Connected Files[^] and applies only to HTML files (*.htm, *.html).
If you want an application to use that feature it must use shell file operations (SHFileOperation function (Windows)[^], IFileOperation interface (Windows)[^] ) instead of Windows API file operations.
I don't know for sure how it is implemented but I guess that it just checks for the existance of matching directories for HTML files and vice versa for directories with the listed extension.
|
|
|
|
|
The HTML filename is used to create the associated directory, so they are connected by name.
|
|
|
|
|
Hello!I'm trying to disable a text box (named m_EarthPermeability) and I want to disable it if a certain value is in Combobox (named m_Layers which gets two values "1" and "2"). Both textbox and Combobox are on the same Dialog window. I have written the code below but the textbox is still in "use" after choosing value "2" in Combobox. Here is the code:
CInputView::CInputView()
: m_Layers(0)
, m_EarthPermeability(0)
void CInputView::OnLinefeaturesFeatures()
{
CInputDoc* pDoc = GetDocument();
CFeaturesDialog DialogWindow;
DialogWindow.m_DialogLayers = m_Layers;
DialogWindow.m_DialogEarthPermeability = m_EarthPermeability;
{
if (m_Layers == 2) {
GetDlgItem(IDC_Permeability)->EnableWindow(FALSE);
}
}
modified 8-Jun-17 5:33am.
|
|
|
|
|
To disable a control you have to call EnableWindow(FALSE) but in your code snippet you are passing TRUE .
I understand also that the text box is part of the dialog and not of your view. Then you have to use
if (m_Layers == 2) {
DialogWindow.GetDlgItem(IDC_Permeability)->EnableWindow(FALSE);
}
It is also not clear if the member variables of your dialog are controls (CEdit , CComboBox ) or values (CString , int ). Your code is correct for value types but not for control types (which is indicated by "a text box (named m_EarthPermeability)").
|
|
|
|