Correct way to derive parse trees, for a given input, to show ambiguity.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
> the start address would be the same, unless the first location has been put in a different location by the sort(int *, int) function.
> sort(v+mid, mid);
Doesn't that ring a bell?
Let me help: 'v+mid' means '&v[mid]' while 'v' means '&v[0]'. Are they equals?
Off: do you ever acknowledge when you get some information, like in post #253 ?
I saw your response as soon as it came, and was and still am working on inability to understand the program, using gdb. In fact, was out of focus on this, and hence could not gain the logic, or understand its workings even; though am conversant with mergesort.
Because of that the gdb could not help me in understanding the working of the program.
But, isn't it sure that gdb helps only if one has clear idea of what is happening, as for such a simple program I faltered in using gdb to understand the program; the reason being that I could not form an idea about the program's workings.
If so, how can your big program be understood by me, is a big confusing issue.
Thanks, that you have fixated on this program. Will soon be back.
Will do the rest of the problems, after problem #4; but this implies that you mean that gdb is an advanced tool, that helps those who can figure out its (someone else's program's) working.
Isn't that a chicken-and-egg issue, as if am totally clear about the logic of someone else's program, then gdb is just an asset, not a neccessity.
I think I know what is the problem: you forgot to take same basic programming courses before starting an advanced course about compilers.
This cannot be solved via gdb, only via hard work.
For such a big answer under #1, posted by you in post #245; cannot understand why you have given such a crispiest reply.
You stated that:
Code:
#1 FILEs like stdout can be buffered, e.g. printf/putc/... etc won't be visible until the end of line (\n). There are different solutions for this, e.g. writing debug-messages to stderr instead.
Or using fflush(stdout) after every debug-print.
Or adding \n to the debug messages.
Or using `setvbuf(stdout, NULL, _IONBF, 0);` at the beginnging
But, that seems to address only the very first measure stated by you, i.e. using the printf() statement.
But, as have already shown earlier, if set breakpoints at lines containing the printf() statement(s), then nothing is printed, till the program exits, and the very last hit at the given breakpoint would print the desired variable value(s).
Such a run of gdb is shown in the attachment, for the given mergesort program.
> But, as have already shown earlier, if set breakpoints at lines containing the printf() statement(s), then nothing is printed, till the program exits, and the very last hit at the given breakpoint would print the desired variable value(s).
No, it has nothing to with breakpoints, it is buffering. That's again something you would learned if you took some beginner programming courses.
> But, as have already shown earlier, if set breakpoints at lines containing the printf() statement(s), then nothing is printed, till the program exits, and the very last hit at the given breakpoint would print the desired variable value(s).
No, it has nothing to with breakpoints, it is buffering. That's again something you would learned if you took some beginner programming courses.
How can not know sthg about printf() statements, but have heard buffering in the context of printf() the first time.
Have done projects of long duration of 9 months, 6 months, & 2 years respectively; in IIT-B, IIT-K, IIT-Kgp as well; and don't know what is this.
Edit: Got much better answer here, but seems need refer to the Richard Stevens' book titled: Advanced Programmng in the UNIX environment; as given an oblivious reference in the answer.
The second & third attachments show the portions found in the book's 3rd edition. But, have not been able to link still to your answer; or even make any meaning out of the same.
Please tell what is the meaning of the address: 0x0000000000400815, in the given webpage, stated in the line obtained after running the command: bt (backtrace):
Code:
#1 0x0000000000400815 in main () at merge.cc:20
also shown in the first attachment.
The reason for asking this is that there is no such address displayed for the sort(), as earlier took it as the start address of the nain(), but then the same should be for the sort() too.
Will do the rest of the problems, after problem #4; but this implies that you mean that gdb is an advanced tool, that helps those who can figure out its (someone else's program's) working.
Isn't that a chicken-and-egg issue, as if am totally clear about the logic of someone else's program, then gdb is just an asset, not a neccessity.
Gdb is not a substitute for your own understanding.
If you cannot understand implementations of simple programming concepts without gdb, then you will not be able to understand them with gdb. Gdb is exactly this in all cases: an asset, not a necessity.
Quote:
Originally Posted by ajiten
Sir, I am a faculty, though with only basic C programming skills.
Faculty or otherwise, more knowledge of gdb is not what you need at this time. You need to take a course, not a refresher, in basic programming in C. Continuing posts about gdb cannot cover for that requirement.
Quote:
Originally Posted by ajiten
How can not know sthg about printf() statements, but have heard buffering in the context of printf() the first time.
Have done projects of long duration of 9 months, 6 months, & 2 years respectively; in IIT-B, IIT-K, IIT-Kgp as well; and don't know what is this.
I intend this in a most helpful way, please do not take it otherwise, but how you can have participated in programming projects over such a period without learning any of the basics, including output buffering, is apparent from your questions here.
You actively avoid learning those basics, looking for quick answers which require no effort on your part and substituting questions about other topics such as endless minutiae about gdb, and as a result you make no useful progress.
Edit: Got much better answer here, but seems need refer to the Richard Stevens' book titled: Advanced Programmng in the UNIX environment; as given an oblivious reference in the answer.
The second & third attachments show the portions found in the book's 3rd edition. But, have not been able to link still to your answer; or even make any meaning out of the same.
Please tell what is the meaning of the address: 0x0000000000400815, in the given webpage, stated in the line obtained after running the command: bt (backtrace):
Code:
#1 0x0000000000400815 in main () at merge.cc:20
also shown in the first attachment.
The reason for asking this is that there is no such address displayed for the sort(), as earlier took it as the start address of the nain(), but then the same should be for the sort() too.
Again, pointless minutia from which you will derive no benefit, deflecting the advice already given.
It is time you make that actual effort. If you do then you will find others, and not only here at LQ, encouraging and eager to help! But if you continue this course you will find that others lose interest and avoid participation in your threads. The reward for those providing help is to see someone benefit from their help. Please reward us!
One additional note on posting: It is preferable to paste only the relevant text of code, error messages and the like, rather than posting screenshots. Relevant text formatted in the common fonts and colors provided by the page is much easier for others to follow. Additionally, if you reach the limit of attachments here at LQ and begin to remove older images to make room for new, you will remove context from existing threads making them of no value to future visitors. Thanks for considering this.
Last edited by astrogeek; 09-21-2023 at 06:53 PM.
Reason: tpoys
Gdb is not a substitute for your own understanding.
If you cannot understand implementations of simple programming concepts without gdb, then you will not be able to understand them with gdb. Gdb is exactly this in all cases: an asset, not a necessity.
Faculty or otherwise, more knowledge of gdb is not what you need at this time. You need to take a course, not a refresher, in basic programming in C. Continuing posts about gdb cannot cover for that requirement.
I intend this in a most helpful way, please do not take it otherwise, but how you can have participated in programming projects over such a period without learning any of the basics, including output buffering, is apparent from your questions here.
You actively avoid learning those basics, looking for quick answers which require no effort on your part and substituting questions about other topics such as endless minutiae about gdb, and as a result you make no useful progress.
Again, pointless minutia from which you will derive no benefit, deflecting the advice already given.
It is time you make that actual effort. If you do then you will find others, and not only here at LQ, encouraging and eager to help! But if you continue this course you will find that others lose interest and avoid participation in your threads. The reward for those providing help is to see someone benefit from their help. Please reward us!
One additional note on posting: It is preferable to paste only the relevant text of code, error messages and the like, rather than posting screenshots. Relevant text formatted in the common fonts and colors provided by the page is much easier for others to follow. Additionally, if you reach the limit of attachments here at LQ and begin to remove older images to make room for new, you will remove context from existing threads making them of no value to future visitors. Thanks for considering this.
Your last line suits you and others of caliber like you, not me; as screenshots help me to remember easily what issues I faced.
Your last line suits you and others of caliber like you, not me; as screenshots help me to remember easily what issues I faced.
It is more about helping others help you and maintaining the integrity of information found here over time for all future visitors. But it is your choice.
> But, as have already shown earlier, if set breakpoints at lines containing the printf() statement(s), then nothing is printed, till the program exits, and the very last hit at the given breakpoint would print the desired variable value(s).
No, it has nothing to with breakpoints, it is buffering. That's again something you would learned if you took some beginner programming courses.
#1> request to give more inputs/hints. Please take into consideration the time that has passed since you posted the given post, and hence I am in need of more inputs.
#2> have issues with the two versions of code, one gives segmentation fault; while the other doesn't. Fail to see the reason why the segmentation fault appears in one only?
bug_c.c : not gives segmentation fault.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
char *noptr;
char i = '5';
*noptr = i;
printf("i: %c, *noptr:%c", i, *noptr);
}
Gives the output as:
Code:
$ ./bug_c
i: 5, *noptr:5
buggy_.c: gives segmentation fault
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
int *ptr = (int *)malloc(sizeof(int));
int *noptr = NULL;
for (int i=0; i<10; i++) {
if (i == 5) {
*noptr = i;
}
else {
*ptr = i;
}
printf("i is %d\n", i);
}
}
Gives the segmentation fault:
Code:
$ ./buggy_
i is 0
i is 1
i is 2
i is 3
i is 4
Segmentation fault (core dumped)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.