How to actually see if the compiler error is Lexical Error or Syntax Error? - c

Is there a way using some tool to see if some program that gave compiler error is Lexical Error or Syntax Error in C. I know mostly which errors are produced by Lexer and which by Parser, but I still have some doubts about some of the unusual cases where I'm confused which is which. So to be kind of sure I want to know that in the compilation error message, but the one I'm using (DEV C) doesn't provide much.

Related

How can I get meaningful error messages from Windows after C program crashes?

When running a program I've written in C, which contains a bug that causes a crash, I'll get the following message from Windows:
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
This doesn't help me at all to find the problem. It can be an array out-of-bounds bug which causes a segfault, or a NULL-pointer dereference, or anything else.
At the end, I find the error by commenting-out code until the rouge code is found.
I'd like to have a faster way to track down these bugs. Is this possible with "Vanilla" Mingw GCC and Windows? Or do I have to install a fancy IDE to get meaningful error messages after crashes?

Can you make Angular tell you when a directive isn't defined?

Just spent the better part of an hour trying to figure out how to use a directive even though I've used it the exact same way before. Turns out I forgot to import the module - -;
It's very annoying since there are no errors in the console.
This reminds me of many errors I've encountered before where an error is thrown but the stack trace all points to code in angular.js even though it originated from my code.
Any recommendations on how to catch these silent/non-helpful errors? I use sublime, but I'm guessing an IDE like webstorm could catch these errors. Might motivate me to switch. Maybe some tool like angular batarang?
This is a huge problem and it's hard to debug. Using the uncompressed versions doesn't really "help": it just makes it possible to get started at all (because without it you don't even get a readable error in the first place).
I've had the best luck using a good debugger like Chrome and a "break on all exceptions" trap. What I've found is that even with the minified libraries, the exception Angular throws will dump you out deep in their error-reporting call stack... but with the entire call chain preserved correctly. If you back out just a few levels and look at the local variables in those functions you can easily find these types of issues because you'll have a variable like 'module' that contains the name of the module it's not finding (for example).

How to compile a program in C with IAR for msp430x5438A when i get the following error?

i am using IAR for msp430xf5438A and when i am trying to compile my program i get an the following error: Internal Error: [TaInstr::Validate]: Instruction does not match requirement. what can i do to solve the this error? thanx!
This is an internal error in the compiler, it is issued when one part of the compiler emits an instruction that it shouldn't have.
If you have the latest version of the compiler, make sure you report this to IAR so that they can fix it. If not, I suggest that you upgrade the compiler.
If you need to continue with the compiler you have, you could try to change the optimization levels or other settings. Alternatively, try to figure out which code triggers the problem and rewrite it.
If you can reduce the problem to a small sample, add it to your question and I'll try to suggest ways to rewrite the code.

How can I catch this "This application has requested the Runtime to terminate it in an unusual way" error in my C program?

I have a C CLI program that crashes and generates this error in Windows 7:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
First, I read somewhere that it could be caused assert statements triggering so as a first measure I replaced them with if statements to catch and log any potential failed asserts. Second, I sprayed the code with printf statements to see where the program exits. Third, I especially made sure that the code doesn't exit anywhere without first logging the exit. The program is threaded so there are quite a few things going on, but nothing too complex.
Now the problem is that the second time I got the error it showed that the program exited outside of my printf statements so I can't tell where it exited.
So two questions:
I suspect I would need to use a proper debugger to see more details regarding the exit, if so, which one?
Are there any other gotchas regarding this sort of error besides the assert statements? I find quite a few C++ blog entries regarding this error, but not too many C ones.
I am using Visual C++ 2008 Express Edition. Also, I am invoking the program in CMD.exe.
First of all, you removed calls to assert which are typically meant to help track down cases where the assumption the programmer makes don't hold? Really? Uhm...
Second of all, are you familiar with the debugger at all? Visual C++ should include an integrated debugger that can, when your program runs in debug mode, not only show you where your process exits from but it can also show you exactly where your program crashes, how it got to that point and what the values of variables where at the time of the crash. Imagine that!
This article mostly talks about C# but the principles are the same.
The message you are getting is from the VC runtime. It happens when an exception is thrown and not caught anywhere.
Compile your program with a debugging debugging configuration (that should be the default) and run in the debugger, and when you hit an unhandled exception, the debugger will break. Under the "Debug" menu, you will find an "Exceptions" item, which will help you fine tune how the debugger responds to exceptions.
Note that in the context of C++ and Windows, 'exception' can mean one of several things; there are the Win32 exceptions, the C++ exception, and VS Structured Exception Handling.
assertions are for fail conditions that you never expect to happen, but can't prove can't happen. You should always be surprised by an assertion. Many (most? all?) implementations of assert() are only compiled in debug configurations and not release configurations.

sample rc file for splint

I am using splint for code checking, and it is throwing out a huge number of warnings. Some of them, I guess can be ignored. I am in the process of creating the .splintrc by trial and error.
My question,
Is there some sample .splintrc file that can be used?
I am using splint for C code, written for a multi-tasking embedded system.
This may not be the greatest of help but I think that you need to provide a bit more information about the type of error messages that you are getting and the target processor/compiler that you are using. The different compilers for embedded target processors all have their own syntax to provide their specific functionality (interrupt processing, transferring to supervisor modes and hardware interfacing are examples)
I have tried to use splint on the MSP430 under IAR and gave up because of the number of warnings and errors that it was throwing when it tried to process the compiler supplied hardware interface definition files. I bit the bullet and purchased Gimpel LINT which came with some configuration files that I could modify to support the precise flavour of compiler and processor I was using.
I have never worked with Splint, but have worked with PC-Lint, and this was my experience as well. Without the compiler configuration files, the lint tool will throw a ton of errors.
You will need to find or create compiler-specific configurations files for your compiler informing the linting tool of the special (non-standard) C constructs and macros that it uses which should be ignored by the linting tool, or you will continue to throw tons of errors.
It is worth the effort, however. Linting your code will help you find errors now instead of during testing when they are harder to find and much more expensive to fix.

Resources