Part of the project I'm working on has me write errors/warnings to a log file. I understand that this is the compiler's job, but the project requires me do this instead. Is it possible to read the errors/warnings that the compilers give instead?
for example: the compiler runs into an error of some type, I want to take that error description and put it into a file.
I don't see any other way to possible catch all the possible errors a program can give without doing a bunch of try/catch statements.
You better ask your Prof exactly what he wants you to do instead of guessing for yourself. Or maybe ask your friends at least.
Without knowing what you're supposed to do ourselves we can't suggest you anything. You will definitely be mislead and turn in a wrong assignment. So first go and find out what your assignment is. Or at least ask your friends 'how' you're supposed to do this.
Also please don't make multiple threads on the same exact topic.. You could have used the previous one you had made on this same d act topic.
I did but people stopped responding to it. also i figured this was a different question.
unfortunately, after the professor "clarified" things, none of my classmates still understand what's going on. we're all in a discord trying to figure it out but to no avail.
He can't ask you to do something not related to what he has taught you. And we don't know what you've been taught. If you don't know and neither do your friends then you should ask the Prof. He would definitely tell you at least 'how' you should be doing the assignment if not for more hints than even that.
You get what I'm saying right? Until you know exactly what you're supposed to do, nobody can help you.
So first get to know what you're supposed to do in the first place and then you can ask for as much help as you want.
If the compiler gives you error, that means the code doesn't compile.
If the code doesn't compile, how can you expect it to write how it doesn't compile on a file?
I'm curious
Is there something I've missed in the previous answers, or are you just hinting at the fact that JLBorges is going to blow my mind with his answer haha?
I know the compiler doesn't fail. But if the program itself is supposed to write to a file all that the compiler outputs AND the program doesn't compile because of errors, I know the compiler will still output all the errors but how can the program run and successfully write on a file all those if it doesn't compile in the first place?
Maybe I'm having a major brainfart, but are you getting what I mean?
> If the compiler gives you error, that means the code doesn't compile.
> If the code doesn't compile, how can you expect it to write how it doesn't compile on a file?
The prospective situation is as follows:
Program A compiler: this program is already compiled without errors and is a ready to run binary
Text B the source code: Pure text of the program to be compiled. The code may contain errors.
Program C compiler driver: this is the program that invokes the compiler A and redirects its output to a file. This program too is already compiled without errors and is a ready to run binary.
The confusion may have arisen because in the toy example (used to illustrate redirection of compiler output to a file), both B and C were coalesced into a single source file; in this case, the source code should be compilable, though the compiler would ideally generate some diagnostic messages (warnings).
Oh that makes sense! How would you user the driver C on a source code though? If you #include it, it will be "part" of the code, therefore you can't call anything from that which you're including?
Would you have to somehow link your source code to another program which then will try to compile your code and save errors and warnings on a file?
> How would you user the driver C on a source code though?
See lines 9 and 10 in the example code. The string cpp_file_name which holds the path to the file (containing the source code) to be compiled is passed to the compiler via a command line argument.