Eclipse CDT does not correctly parse 'unsigned int myVar;' - eclipse-cdt

I encounter strange problem with Eclipse CDT Helios under Ubuntu
The screen shot is here http://imgur.com/0saop
int MiniMsg::parseChecksum() {
unsigned int dint; // this if flagged as syntax error by Eclipse only!!
uint32_t d32;
return parseItem(chkStart, chkEnd, checksum);
}
The definition of 'dint' is not recognized and flagged as syntax error.
Actually any definition of the form 'signed/unsigned type var' is not recognized...
Any ideas?

Usually a yellow squiggly means a compiler warning, and guessing by the fact that that variable is never used, it is probably complaining about that.
The warning would be something along the lines of:
foo.c:3: warning: 'unsigned int dint' defined but not used

Related

I'm getting tautological compiler errors. How am I supposed to fix "argument of type "X" is incompatible with parameter of type "X"?

The specific details in my case: I'm using MSVC with AMD's vulkan memory allocator, which is a stb-style single header file. (So you include it in your project like:
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"
within a single compilation unit to compile it, and just
#include "vk_mem_alloc.h"
in any file that needs to use it.)
Anyways:
Some examples of specific errors I'm getting are:
argument of type "VmaDeviceMemoryBlock *" is incompatible with parameter of type "VmaDeviceMemoryBlock *"
and
a value of type "VmaSuballocationType" cannot be assigned to an entity of type "VmaSuballocationType"
and
declaration is incompatible with "void VmaBlockMetadata::PrintDetailedMap_Allocation(VmaJsonWriter &json, VkDeviceSize offset, VmaAllocation hAllocation) const"
when the definition is
void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter& json,
VkDeviceSize offset,
VmaAllocation hAllocation) const
These errors, as well as many others that aren't obviously broken, absolutely litter the file. Even stranger, I can build the program and it compiles and runs without issue. Its populating of my error window with this noise is totally undermining the error window's usefulness. I'm also now getting other strange errors throughout my code, and I'm unsure how to proceed.
I got this exact same set of errors using visual studio 2019. The error in my case was using uniform initialization with an implicit cast.
I needed to change
uint32_t uniformOffset{ pad_uniform_buffer_size(sizeof(GPUSceneData)) * frameIndex };
to
uint32_t uniformOffset{ static_cast<uint32_t>(pad_uniform_buffer_size(sizeof(GPUSceneData)) * frameIndex) };
because pad_uniform_buffer_size returns size_t and I was trying to implicity cast it to uint32_t with uniform initialization.
I have no idea why the error manifested itself in that vma file, but this was the solution in my case.

Using for_each_process() in my program prevents me from compiling, compiler says semicolon expected?

I'm trying to write a very simple piece of code for a class, but I'm just stumped as to why I can't compile it. Sorry if this is a duplicate or silly question, but I couldn't find any others that answered this for me. My full program is pasted below. When I try to compile, I get the following error:
test.c: In function 'main':
test.c:7:27: error: expected ';' before '{' token
Here's the code:
#include<stdio.h>
#include<linux/sched.h>
#include<linux/kernel.h>
int main(){
struct task_struct *task;
for_each_process(task){
printf("I found task: %d\n", task->pid);
}
return 0;
}
I feel like I'm missing something painfully obvious, can anyone point out what the problem is here? I've tried initializing the 'task' object as NULL and using a simpler printf statement that just prints 'test', but nothing I've tried has fixed this compilation error.
The macro has been moved to <linux/sched/signal.h> in this commit c3edc4010e9d102eb7b8f17d15c2ebc425fed63c in 2017. (https://github.com/torvalds/linux/commit/c3edc4010e9d102eb7b8f17d15c2ebc425fed63c).
(For someone who has trouble in compiling for this reason.)
The preprocessor token you are using for_each_process is either not defined, or not defined to do what you think it does.
Every C++ compiler I've used can be told to dump the post-preprocessing output. If you pass the flag that makes this happen when building your source file, you'll see the code that the compiler is seeing and screwing up on.
gcc -E clang -E or the /E flag in visual studio (heh) for example.
As #Ulrich has mentioned above, apparently that macro is only available within the kernel. Attempting to read <linux/sched.h> directly and determine this is challenging, as there are many, many ifdef/endif pairs.

Why does LLVM complain about missing function prototypes?

LLVM 2.1 has an option that enables warnings for "missing function prototypes." When enabled, the warning will complain about a file like this:
double square( double d )
{
return d*d;
}
void main()
{
// ...
}
The function "square" will trigger a warning because it is defined without having been declared (prototyped). You can eliminate the warning thus:
double square( double d );
double square( double d )
{
return d*d;
}
void main()
{
// ...
}
I've programmed in C++ for twenty years and I've never seen a warning like this. It does not seem useful to me.
By default, this warning is enabled in new Mac console projects (at least) in Xcode 4.1. Evidently someone found it useful enough to first implement it and then enable it by default.
Why is this a useful warning? Why does LLVM have it as an option? Why is the option enabled by default on Xcode?
The compiler uses the prototype declaration to match types for the function definition.
If you are writing the prototype in a header(interface) file and the implementation in the source file then this warning (by forcing you to provide a declaration, effectively) would prevent you from making a typo error where function definition is different than the one in declaration.
Though, without such an warning, you would get the errors while linking. One might end up wondering what the actual problem is(n number of reasons for linking errors).
The warning during compilation stage is much better indication of error than a linking error.
If could be useful to make sure every function is either visible from some header, or static.
I had cases where two files were linked together, even though none of them used the same header file.
Take this example:
int test()
{
return 0;
}
If there's no header, you can have a second file which does:
extern int test();
test();
If you are writing a library, this warning could tell you that someone could be using this function even if they were not supposed to, since this function is in no header. They should have been marked as static.
Prototype of "int test()" should be "int test(void)" then it's OK.

Strange visual studio 2008 C++ compiler error

I have three lines of code:
//int pi;
activation->structSize = sizeof(rmsActivationT);
int pi; //program wont compile with this here
every time I uncomment the second int pi and comment the first int pi I get this error: syntax error : missing ';' before 'type'. When i uncomment this first int pi and comment the second int pi, my compiler doesn't complain anymore. This error has been bothering me for almost a full day now any ideas would be great.
Thanks
Visual studios 2008
Windows XP 32 bit
Are you, perhaps, compiling the code as C instead of C++? C (prior to C99, which Visual Studio doesn't support) required that all definitions in a block precede any other statements.
I had the same problem.
The compilation errors were:
*main.cpp(325): error C2601: 'FLAG' : local function definitions are illegal
main.cpp(323): this line contains a '{' which has not yet been matched
main.cpp(326): fatal error C1075: end of file found before the left brace '{' at 'main.cpp(323)' was matched*
But there was nothing wrong with my code. I counted all brackets and the number matched. There weren't any function inside another function.
I solved it by removing all "//" comments from the source code. It seems that the reason for that is bad line formatting which causes the compiler to miss a line break, so the line after a comment is treated as a comment as well.
For example:
// This is a comment
This_is_a_line;
is treated as:
// This is a comment This_is_a_line;

New to C/C++ Using Android NDK to port Legacy code, getting compile errors

I have been trying to take some old Symbian C++ code over to Android today using the NDK.
I have little to no C or C++ knowledge so its been a chore, however has to be done.
My main issue is that I'm having trouble porting what I believe is Symbian specifi code to work using the small C/C++ subset that is available with the Android NDK.
Here is a picture of the compilation errors I'm getting using cygwin
I was wondering if anyone could point me in the right direction on how to deal with these errors? For instance is TBool/Int/TUint/RPointerArray/RSocket a Symbian primitive and thats why it wont compile or is it something else?
Also what is ISO C++?
Any tutorials, guides or tips and help would be greatly appreciated.
EDIT:
Here is a code snippet from the .h file I am trying to import followed by the output for the snippet from the compiler.
Could someone guide me on how I would port this Symbian specific code to normal C++?
If I got an idea of whats Symbian specific and how to change it I believe I could change then begin to port the rest myself
#ifndef __RTPSTREAM_H__
#define __RTPSTREAM_H__
class CRTPParser;
class MDataRecorderObserver
{
public:
virtual void DataRecorded(const TDesC8& aData, TUint aCodec, TUint aFramesizeMs)=0;
};
class MRTPStreamDataObserver
{
public:
virtual void AudioDataSent()=0;
virtual void DataReceived(const TDesC8& aData,TUint aCodec, TBool aMarker, TUint aSeq, TUint aTime)=0;
virtual void DataReceived(const TDesC8& aData)=0;
};
$ make APP=ndk-socket
Android NDK: Building for application 'ndk-socket'
Compile++ thumb: socket <= apps/ndk-socket/project/jni/rtpstream.cpp
In file included from apps/ndk-socket/project/jni/com_ciceronetworks_utils_RTPJn
i.h:2,
from apps/ndk-socket/project/jni/rtpstream.cpp:4:
build/platforms/android-3/arch-arm/usr/include/jni.h:489: note: the mangling of
'va_list' has changed in GCC 4.4
In file included from apps/ndk-socket/project/jni/rtpstream.cpp:11:
apps/ndk-socket/project/jni/rtp/RTPStream.h:15: error: ISO C++ forbids declarati
on of 'TDesC8' with no type
apps/ndk-socket/project/jni/rtp/RTPStream.h:15: error: expected ',' or '...' bef
ore '&' token
apps/ndk-socket/project/jni/rtp/RTPStream.h:23: error: ISO C++ forbids declarati
on of 'TDesC8' with no type
apps/ndk-socket/project/jni/rtp/RTPStream.h:23: error: expected ',' or '...' bef
ore '&' token
apps/ndk-socket/project/jni/rtp/RTPStream.h:24: error: ISO C++ forbids declarati
on of 'TDesC8' with no type
apps/ndk-socket/project/jni/rtp/RTPStream.h:24: error: expected ',' or '...' bef
ore '&' token
apps/ndk-socket/project/jni/rtp/RTPStream.h:24: error: 'virtual void MRTPStreamD
ataObserver::DataReceived(int)' cannot be overloaded
apps/ndk-socket/project/jni/rtp/RTPStream.h:23: error: with 'virtual void MRTPSt
reamDataObserver::DataReceived(int)'
apps/ndk-socket/project/jni/rtp/RTPStream.h:30: error: 'TInt' has not been deca
red
By "ISO C++", the G++ compiler means "The C++ standard".
This looks like the usual G++ error spew when it gets confused. Typically only the top error message is meaningful, and then the rest is what the compiler prints out because it was confused. The odd thing is that the initial error about "expected class name before '<' token" is itself more typical of error spew than real errors. It's perhaps useful to have a look at that point in the code and see what it says and whether there's anything strange or compiler-specific there.
Also, from a Google-search, it looks like the initial note about va_name mangling is just informative and very unlikely to cause a problem in this case -- and, specifically, is certainly not going to cause the rest of these compiler errors.
Edit: Based on the revised error output and source code that you posted, it looks like the error is simply that this code is using the "TDesc8" data type without it first being declared, and the rest is likely to be followon from that. According to the information I could find online in the Symbian documentation, code that uses that type should have a #include <e32des8.h> line to include the relevant header. Does the code you are compiling include that header?