|
|
Hi Stefan. Thanks for your answer. It is very smart way to contour the problem. I think I would never figure out a solution like that . The reason of so many levels is because the s1 is an identity with a lot of different information and I must have access to them in every function (I thought this was the best way) but I will take a chance in C++. I think in my situation will help me a lot.
Best regards
Filipe Marques
|
|
|
|
|
You appear to be facing a problem that is not related to the programming language or it's (lack of) features: when your function needs to parse a data structure of such complexity, the question arises why it needs to know about the entirety of this structure? Wouldn't it be sufficient if e. g. the caller passed struct1->struct2->struct3 to the function as an argument, so it wouldn't need to dig through the top layers to start with? If this is true, then you need to redesign the function signature so it requests only pointer(s) those parts of the data structures that it needs to access.
Or, if your function really needs to know about all parts of that data structure, then it might be doing too much in just one function, and you should consider splitting it up into multiple parts.
Or, if your function is small, and really can't be split up any further in a sensible way, then the question arises why are these data values spread so far out over different parts of the data structure? Maybe it is the data structures after all , that need to be redesigned, so that related values are stored within the same (sub-)structure!
All of this is based on the principals of "locality of concern" or "information hiding". You can google on those expressions for more information.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thank you Stefan, I didn't know about "locality of concern" or "information hiding". In these couple of days I have been review the code and yes, I am passing information that I am not really using in my functions and I am making all of them available to the user, unnecessarily. Right now I am redrawing the code ... again
Best regards
Filipe Marques
|
|
|
|
|
It becomes a "depends" question and by that I mean it depends on why such deep nesting is required. To me your code looks like it either needed a variant record or simple database functions put over the top of it.
To give you the idea lets look at a simple example that would nest something like what you have. Lets say we have database of books that were linked in memory. Done in your sort of nested format to access a given line would be like this
section struct->book struct->page struct-> Line struct->actual text on that line
So you could imagine an example something like
Fiction->War and Peace->page 200->line 20->text
That structure points to the text on the 200th page, line 20 of the fictional book called "war and peace"
There is nothing wrong with that but from a programming sense it would have been much more desirable to setup a basic interface.
Define your structures Section, Book, Page, Line as per normal but make functions to do the work
book* SelectBook (book* Booklist, section, title);
page* MoveToPage (book* SelectedBook, int PageNum);
line* MoveToLine (page* SelectedPage, int LineNum);
So your code would now become something like
book* MyCurrentBook;
page* CurrentPage;
line* CurrentLine;
MyCurrentBook = SelectBook(BookList, Fiction, "War and peace");
Currentpage = MoveToPage(MyCurrentBook, 200);
CurrentLine = MoveToLine(Currentpage, 20);
What you get for the cost of building the functions is code clarity as well as being able to contain error checks inside the functions. You can take the idea even further if you like and start writing object like code in C.
So my ultimate view of your macro depends on what your nested structure list is for and could it have been done a better way. If it couldn't then using the MACRO is perfectly fine.
|
|
|
|
|
Hi Leon, thanks for your answer. What you described here is exactly my problem. The problem is that I always program in C++ and the few C programs were really small ones. The way to think is a little different and I always think in an object way. I decided to migrate to C++. The code became cleaned and easy to read. One more time, thanks for your answer and I am sorry to take so long to answer Best regards Filipe Marques
|
|
|
|
|
Hi!
I am a new one for c++. I have to plane create a new adblock application for the browsers(Firefox, Chrome and safari). I don't have any idea. Please anyone help me and guide me. Its urgent.
|
|
|
|
|
It would probably be best to create add-ins for the different browsers. You'll have to research and study how to create add-ins for Firefox, Chrome and Safari.
I know that to develop for the Apple platform requires you to join their developer program which costs money.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Is there anyway to do this app?
|
|
|
|
|
Of course there is. But you can't learn how from some forum posts. You have to study how to create add-ins for the specific browsers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks for your reply...
I will study.
Thanks again.
|
|
|
|
|
Seems someone down voted the question so I up voted it just to offset.
Member 8041178 wrote: I am a new one for c++.
If you are really new to programming and to C++ then I suggest you start with something which will have a smaller scope.
For example attempt to create your own browser first. Or your own server that your browser can connect to and display something.
|
|
|
|
|
jschell wrote: Seems someone down voted the question so I up voted it just to offset.
You up-voted a question which basically reads: "I want to write an application to do X, but I don't know how. Someone do it for me. It's urgent!"?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Someone do it for me. I
I don't consider "Please anyone help me and guide me" to be the same as "do it for me". Not even really close.
And I basically ignore "urgent" requests so intent there means little.
|
|
|
|
|
Hi All:
I wanna implemented a application with MFC, when clicke a button on any application, select a icon on the desktop then play sound.
I try to implement similar function with ON_WM_LBUTTONDOWN(), but not satisfied my request. If I click everywhere on desktop, it will play sound too.
How do I implement this application? Does any keyword or reference?
My English is not good. Please forgive me.
Best regards, Victor
|
|
|
|
|
|
But, I added WM_LBUTTONDOWN into Mousehookproc, it does not work.
which do I add in, WinProcHook or Mousehookproc? if I add into WinProcHook, how can I get the button?
Thanks for your help, Victor
|
|
|
|
|
You'll have to use the concept of 'hook'.
Please refer to hook details here. You can use this[^] article for your reference.
|
|
|
|
|
But, I added WM_LBUTTONDOWN into Mousehookproc, it does not work.
which do I add in, WinProcHook or Mousehookproc? if I add into WinProcHook, how can I get the button?
Thanks for your help, Victor
|
|
|
|
|
Please verify that the Hook got installed properly. Once the hook is installed, you should be able to get the messages.
When the mouse event is received, you can check the window handle. Using that window handle, identify the class type of the window.
|
|
|
|
|
Greetings to all friends.
I want to develop an application that decrypt an exe file format and save it in RAM and then run it . Developed application does not allow the save decryption output to a file. To run an exe application that is loaded to RAM I have no idea. Please guide me.
Thanks to all friends
|
|
|
|
|
As far as I am aware, there is no Windows function that allows you to do this. The LoadLibrary function[^] can load a module from file storage into memory, so that you can execute it directly, but there is no facility for loading direct from RAM.
Veni, vidi, abiit domum
|
|
|
|
|
Windows, like most modern operating systems, uses virtual memory to execute a program.
In this scheme, only data that needs to be modified is loaded into RAM.
Read-only data and code are directly mapped from disk and not loaded into RAM.
The best that you can do is create a RAM disk and save the output to a file on the RAM disk.
To a program, this RAM disk would be very similar to an ordinary disk drive.
Here is a list of of available RAM drive software - List of RAM drive software[^]
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
|
Hi All,
I'm in begining of implementing a software but i need to make sure the software should be OS (operating system) independent. So which design pattern i need to implement.
Langauge used - C++
Thanks,
Manisha
|
|
|
|