|
The laughing at me smiley face, etc. Wasnt making fun? Ok.I did explain. I posted a direct link straight to my problem. I was unaware discussions were for questions too. I only posted the discussion to raise awareness of my question. I did not realize I was doing something wrong. And if you did in fact read through the whole thread you would see that I mentioned that on multiple occasions. I am new to this site and those of you who are not should just guide others and explain processes to them if they dont quite get it. Not attack them over and over again.I still don't see how posting a link to a question is posting it twice, just gives another access point. Now, please stop attacking me and go on about your business. I will not post here after this thread again for quite some time if ever. I will stick to the area labeled questions.
|
|
|
|
|
MalDrHoop wrote: The laughing at me smiley face, etc. Wasnt making fun? No.
MalDrHoop wrote: I was unaware discussions were for questions too. Did you read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^]?
MalDrHoop wrote: And if you did in fact read through the whole thread you would see that I mentioned that on multiple occasions. Not clearly.
MalDrHoop wrote: I still don't see how posting a link to a question is posting it twice Because that is the protocol here. If you post a question in one place and then post somewhere else pointing to the question you are adding unnecessary clutter to the forums.
MalDrHoop wrote: Now, please stop attacking me and go on about your business. No one is attacking you, we are just trying to expalin how this site works.
Veni, vidi, abiit domum
|
|
|
|
|
A laughing smiley face is making fun.
I did look over that briefly, after realizing it was at the top of the forum. My question doesn't seem suitable for a thread if you ask me. Have you seen the size of it? It contained two codes, inputs, and outputs for 100 iterations. And my deduction still would say now that posting a question so large would not be appropriate for a thread.
I did clearly say many times that I was new and unsure how to use threads after I saw that he misunderstood. His first reply seemed to me like he had looked at my program and I didn't catch otherwise till later on. I had asked if anyone could see any problems with my program and his reply was not that I can see. So I thought he had seen it and didn't find an issue.
I don't see how trying to get someone's attention directed to a question that required some much needed help was such an addition of clutter.
When you keep on my case with harshness instead of kind guidance then yes that is attacking in my book.
|
|
|
|
|
MalDrHoop wrote: A laughing smiley face is making fun Not in this forum; it indicates that the writer is not being too serious.
MalDrHoop wrote: I don't see how trying to get someone's attention directed to a question that required some much needed help was such an addition of clutter. Because it is an unnecessary message. All questions can be viewed by all members, and will be answered as and when someone has something useful to respond. If everyone who posted questions added messages such as you did, then the forums would be overflowing with messages that just add confusion.
MalDrHoop wrote: When you keep on my case with harshness Is it harshness to try and explain the proper way of using these forums?
Veni, vidi, abiit domum
|
|
|
|
|
And those desired results are what? Have you stepped through it using the debugger?
"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 everyone,
Right now, I am creating a project in C and at some point I am accessing, multi times during the source code, to a struct with a lot of nested structs, like this
struct1->struct2->struct3->struct4->struct5->value1
struct1->struct2->struct3->struct4->struct6->value2
What I created was a macro to clear the code:
#define ACCESS (struct1->struct2->struct3->struct4)
ACCESS->struct5->value1
ACCESS->struct6->value2
My question is: This is a good practice or a very very very bad practice?
Best regards,
Filipe Marques
|
|
|
|
|
Bad practice is using such chains of pointers. You should check if that can be avoided. If structure members can share memory locations, you should use unions.
I would use a variable instead to make the code more readable and avoid the chain:
struct4_t *struct4 = struct1->struct2->struct3->struct4;
s5val = struct4->struct5->value;
|
|
|
|
|
Thanks for your answer Jochen. I have been thinking better and maybe I will accept the Richard suggestion because the real situation is something worst
struct1->struct2->struct3->struct4[struct5->struct6->struct7]
Not pretty ah?.
Best regards
Filipe Marques
|
|
|
|
|
Very bad practice, it makes it difficult to understand or maintain the code; you should look closely at your design. You may also benefit from upgrading to C++ and using classes instead of structs.
Veni, vidi, abiit domum
|
|
|
|
|
Hi Richar, thanks for your answer. Yeah, the code is getting realy hard to maintain and each little change I do, it is a nightmare.
Best regards
Filipe Marques
|
|
|
|
|
Not sure if some C-Compilers accept functions within a struct like in C++ Classes, but if not, you could just define a global function instead of a member function. You could then also integrate some sanity checks to make your code safer, e. g.:
Struct4* haul(Struct1* s1) {
if (s1 && s1->struct2 && s1->struct2->struct3 && s1->struct2->struct3->struct4)
return s1->struct2->struct3->struct4;
else
return 0;
}
...
Struct4* s4 = haul(struct1);
if (s4) {
s4->struct5->struct6;
...
}
Of course the question is why you need so many levels of indirection
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)
|
|
|
|
|
|
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.
|
|
|
|