Parse issue Expected identifier or ')' in _types.h - objective-c

Suddenly I'm getting an error in _types.h on the line with typedef. How can I track this down?
#ifdef __GNUC__
typedef __signed char __int8_t;
#else /* !__GNUC__ */

This is pretty much always caused by a syntax error just prior to whatever included the file with the actual error.
So, have a look in the file that (indirectly) included _types.h. You likely have an unbalanced (.

Usually these cryptic errors in system header files result from your having other code (perhaps in another header file which was #import'ed earlier) that is missing a closing parenthesis. Often whenever you get strange compile errors, you have to look at the lines of code that the compiler encountered before the reported line and see if that earlier code was properly terminated.

Related

How can I tell cppcheck to ignore inline assembly?

We have a file within inline assembly for a DSP. Cppcheck thinks there are a load of "variable assigned but not used" lines in the assembly.
Is there any way to tell it to skip checking the inline assembly sections? I couldn't see anything obvious in the manual, and it is a bit tedious to have to suppress each line in turn (t
Here's an example of some of the the offending lines. It's a context save routine.
inline assembly void save_ctx()
{
asm_begin
.undef global data saved_ctx;
.undef global data p_ctx;
asm_text
...
st XM[p0++], r0;
st XM[p0++], r1;
st XM[p0++], r2;
st XM[p0++], r3;
st XM[p0++], r4;
st XM[p0++], r5;
st XM[p0++], r6;
...
I can turn off the messages with
// cppcheck-suppress unreadVariable
before each line, but it would be better to just tell cppcheck to skip the whole inline assembly section.
Is there any way I can do this, or will we just have to accept lots of repeated comments?
Somewhat counter-intuitive, but thanks to #DavidWohlferd for pointing me the right way.
-D__CPPCHECK__ doesn't do the right thing. It tells cppcheck to only check blocks with __CPPCHECK__ or nothing defined, i.e. it completely turns off the combinatorial checking. However there is a simple but counter-intuitive solution using -U.
Wrap the block with
#define EXCLUDE_CPPCHECK
#ifdef EXCLUDE_CPPCHECK
...
#endif // EXCLUDE_CPPCHECK
Now if you call cppcheck with -UEXCLUDE_CPPCHECK it will skip that block (even though the #define is just before it!) but still do all the other combinations of #define which are used in #if.
Thank you David and Drew.
According to man page (didn't try myself) you can add command line options:
--suppress=<spec>
Suppress a specific warning. The format of <spec> is: [error id]:[filename]:[line]. The [filename] and [line] are optional. [error id] may be * to suppress all warnings (for a specified file or files). [filename] may contain the wildcard characters * or ?.
--suppressions-list=<file>
Suppress warnings listed in the file. Each suppression is in the format of <spec> above.
I.e. in your case --suppress=unreadVariable:all_dsp_asm_*.cpp and switch it completely for those particular files. Which is IMO usable, as you can put all the DSP inline asm things into separate file, so it will not affect your ordinary cpp check.
Or in worst case use the suppression-list listing file, where you may list particular lines ad absurd I guess, to cover whole inline parts.
I don't see how to inline it in the source, looks like it may affect only single line.
Checking probably more up to date version of manual here, you can exclude whole file also by -i<filename> (second page).
The options above are at page 11.

How do I get XCode to build a project with Objective-C++ in it?

I added the Scintilla framework successfully to my XCode project (i.e. it finds the header files correctly), but because it is written in Objective-C++ it doesn't compile. I get 8 syntax errors because of ::s. I already found you can't include Objective-C++ from a pure Objective-C file, so I changed the file extension to mm. It still gives me the same 8 errors.
I also changed the file type (of the importing file) to sourcecode.cpp.objcpp.
The relevant lines of code (with the errors in comments - the line numbers are from the original file, so without the errors in the comments):
ScintillaView.h
// Line 47-49
#protocol ScintillaNotificationProtocol
- (void)notification: (Scintilla::SCNotification*)notification; // 4 errors on this line:
// 1. expected type-specifier
// 2. expected ')'
// 3. expected identifier
// 4. expected ';'
#end
// [snip]
// Line 131
- (void) notification: (Scintilla::SCNotification*) notification; // The exact same errors.
When copying this code I noticed the :: operator is used a few more times in the file, so somehow the parser is only able to match it succesfully in certain places.
Once more, this code is not mine, but taken from the Scintilla Cocoa Library.
(See here for more info: http://www.scintilla.org/)
XCode 3.2.6, Mac OS X 10.6.8
Adding
typedef tdSCNotification Scintilla::SCNotification
Before the first offending line revealed that there was no type called SCNotification in that namespace. So I searched through the included header files (which, luckily, count only three) for namespace Scintilla {. It was in the first included header file, Scintilla.h. But it looked like this:
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
and
#ifdef SCI_NAMESPACE
}
#endif
So I assumed SCI_NAMESPACE wasn't defined. I added #define SCI_NAMESPACE to Scintilla.h somewhere online 45 and it worked. Almost. I got another error message:
Framework not found Scintilla
Command /Developer/usr/bin/llvm-g++-4.2 failed with exit code 1
I think this has to do with how I added the framework to my project, so it should be a separate question.

Missing Section in POLINK warning from HLA code

I have an error that I looked around the internet quite a bit yet I have yet to find a real solution to this problem. Here is the error message I get from my computer (Win 7):
POLINK: warning: /SECTION:.bss ignored; section is missing.
With this error, obviously comes some code. So what I am trying to do with the code is see what happens wham you mix signed and unsigned variables in the same calculation. I am sure this error shows up in other situations as well, but I haven't bothered to do too much about it. Anyways, here's the code:
program example;
#include ("stdlib.hhf")
static
unsigned: uns16;
dummy:byte;
begin example;
stdout.put ("Enter an int between 32 768 and 65
525");
stdin.getu16();
mov (ax, unsigned);
stdout.put (
"You entered",
unsigned,
". If this were a signed int, it would be: "
);
stdout.puti16 (unsigned);
stdout.newln();
end example;
Any help would be appreciated as to where this problem originates so anything would be appreciated.
Thank you
Firstly this is not an error message it is a warning.
As evident from POLINK: warning: /SECTION:.bss ignored; section is missing.
The linker called POLINK complains that the BSS section is missing, because in the assembly your HLA code snippet generates it is.
In order to make it go away, you can change HLA to use another linker that doesn't generate the warning message or you can add HLA code which populates the BSS with a dummy or placeholder variable.
The code to add would be
storage
dummy:byte;
before the begin example line.
Reference
- POLINK: warning: /SECTION:.bss ignored; section is missing. from MASM forums

How to suppress warnings for 'void*' to 'foo*' conversions (reduced from errors by -fpermissive)

I'm trying to compile some c code with g++ (yes, on purpose). I'm getting errors like (for example):
error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
adding -fpermissive to the compilation options gets me:
error: invalid conversion from 'void*' to 'unsigned char*' [-Werror=permissive]
which seems to be a error because of -Werror, however adding -Wno-error=permissive -Wno-permissive results in:
error: -Werror=permissive: no option -Wpermissive
error: unrecognized command line option "-Wno-permissive" [-Werror]
How do I disable warnings (globaly) for conversions from void* to other pointer types?
You cannot "disable warnings for conversions from void* to other pointer types" because this is not a warning - it is a syntax error.
What's happening here is that you are using -fpermissive which downgrades some errors - including this one - to warnings, and therefore allows you to compile some non-conforming code (obviously many types of syntax errors, such as missing braces, cannot be downgraded to warnings since the compiler cannot know how to fix them to turn them into understandable code).
Then, you are also using -Werror which upgrades all warnings to errors, including the "warnings" that -fpermissive has turned your error into.
-Wno-error is used only to negate -Werror, i.e. it causes -Werror to treat all warnings as errors except the warnings specified with -Wno-error, which remain as warnings. As the -W flag suggests, both these flags work with warnings, so they can't do anything with this particular issue, since what you have here is an error. There is no "warning" for this kind of invalid conversion that you can switch off and on with -Werror because it's not a real warning - it's an error that -fpermissive is merely causing to be treated as a warning.
You can compile your non-comforming code, in this case, by using -fpermissive and not using -Werror. This will still give you a warning, but like all warnings, it won't prevent successful compilation. If you are deliberately trying to compile non-conforming code, then using -Werror makes no sense, because you know your code contains errors and will therefore result in warnings, even with -fpermissive, so specifying -Werror is equivalent to saying "please do not compile my non-conforming code, even though I've just asked you to."
The furthest you can go to get g++ to suppress warnings is to use -fsyntax-only which will check for syntax errors and nothing else, but since what you have here is a syntax error, that won't help you, and the best you can do is have that turned into a warning by -fpermissive.
How do I disable warnings (globaly) for conversions from void* to
other pointer types?
Well it might require direct interaction with compiler's code. This is probably not what you want. You want to fix your code. First, these are not warnings but errors. You need to cast void* as you can not convert a void* to anything without casting it first (it is possible in C however which is less type safe as C++ is).
For example you would need to do
void* buffer = operator new(100);
unsigned char* etherhead = static_cast<unsigned char*>(buffer);
^
cast
If you want a dynamically allocated buffer of 100 unsigned char then you are better off doing this
unsigned char* p = new unsigned char[100];
and avoiding the cast.
void pointers

Objective C, CABase.h file error

I hate Xcode 4! It crashes all the time and finally it gives me an error in CABase.h file which is an library header file that I am not allowed to modify..
I don't even know how this file is broken.
How to fix this problem? It complains like
"Expected *before*
Expected '=',',',';','asm' or '_attribute_' before 'extern'
Also, how can I completely remove Xcode on my Mac and re-install?
You probably just have a simple error, perhaps in a header which is included prior to CABase.h. Use a "divide and conquer" strategy to locate it.
To answer your last question:
$ sudo /Developer/Library/uninstall-devtools –mode=all
This happened to me just because I had the letter 's' at the beginning of one of my implementation files. I must have missed the cmd key when cmd+s for saving the file. Luckily, another compile error discovered this and removing the 's' fixed both errors.
For example,
s//
// GraphingViewController.m