Eclipse shows syntax error when using PRId64 from inttypes.h - 32bit-64bit

When I do
#include <inttypes.h>
long long value = 0;
printf("An 8 byte long integer value: %"PRId64".", value);
Eclipse shows me a syntax error in the printf line. Anybody knows how to get rid of it? This is the only way I know to have a printf working on both 32-bit and 64-bit architectures and Eclipse errors every few lines make it quite hard to see the real issues.
Thanks!

The question was answered here.
You need to add __STDC_FORMAT_MACROS in Project Properties->C/C++ General->Paths and Symbols.

Related

`_naked`: Trying to compile legacy 8051 (FX2) code with SDCC, newer version stumbles

I have legacy code for an embedded 8051 core (in a cypress FX2) that used to compile with other versions of SDCC. However, current SDCC doesn't know the _naked qualifier:
delay.c:27: syntax error: token -> '_naked' ; column 21
as triggered by
static void
udelay1 (void) _naked
{
_asm ; lcall that got us here took 4 bus cycles
ret ; 4 bus cycles
_endasm;
}
and other occurrences.
As _naked practically is supposed to tell the C compiler to "nah, ignore the fact that you're a C compiler and understand that you'd need to save frame context", I don't feel like I should just #define it away.
Is there any solution to this? Should I just go ahead and manually inline the assembler wherever a _naked function is used? I feel like I'd betraying the compiler on a CALL there, and that would change the timing.
_naked was replaced by __naked in newer versions of SDCC. Same applies to asm/__asm, at/__at, interrupt,bit,xdata/__….
So, this turned out to be an exercise in regex replacements.
I'm still having linker/ranlib/mostly ar problems, and CMake ignores what I instruct it to use as compilers, but oh well.

Autoit ImageSearch and Windows 7 Unterminated String

I just found ImageSearch library, very cool!
But when I tried to test it out I got strange errors, the only one I can't seem to get around is:
Line 46 (File "C:\...\ImageSearchDLL\ImageSearchTest.au3"):
U1A%a]A%01/4' Error: Unterminated String.
Thats the error but my script doesn't even have 46 lines so it must be in something its importing, here's the test script:
#include <MsgBoxConstants.au3>
#include "ImageSearchDLL.dll"
#include "ImageSearch.au3"
local $x, $y, $search
$search = _ImageSearch('search.bmp', 0, $x, $y, 0)
if $search = 1 then
mousemove($x,$y)
EndIf
MsgBox($MB_SYSTEMMODAL, "imagesearch", $x, 10)
its not line 46 in the imageSearch.au3 either.
So! my thinking is its a problem with the DLL.
I'm on windows 7, could it be that imagesearch.dll is not compatible with windows 7?
That would make me quite sad. Can someone help me? Perhaps there are newer alternatives I'm unaware of. Thanks so much!
You can not include .dll files on autoit. I don't know why you are using it.
The UDF calls it by itself.
The error must be on the version you are using. Just update it or look for a version more up to date.
Try to compile your script using x64 or x86 compiler, depending on your system. Then executing it using yourscript.exe
https://www.autoitscript.com/forum/topic/177190-imagesearch-gives-unterminated-string/
I found a "fixed" version that works with windows 7 here on the forums somewhere. attached is the file I found. I have no idea what was done to fix these unterminated string errors I kept getting but I must have been using a very old version or something. hope this helps others!

Arduino IDE maximum PROGMEM char array length

I am trying to use a single 4KB string in my arduino sketch but this always seems to give a whole bunch of java errors in the console and never compiles. I believe, I am using it correctly:
const char sequence[] PROGMEM = {"0F0FF0 ... 0F0F0FF"};
By trial-and-error I determined that the maximum length I can get to compile successfully is 1104 characters. This doesn't seem to make much sense. Is there some unknown limitation in the compiler or is it an issue with the IDE? I'm using 1.0.5 but I get the same results in 1.6.5 as well. I'd really rather not split the array. Reading online, the size limit should be 32KB, which is far higher, than what I need.
Any help or explanation appreciated, please and thank you.
It's a limitation of the IDE, not the compiler. If you make it a single string still, but use C's string concatenation, it will compile. eg.
const char sequence[] PROGMEM = {
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
...
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
};

OpenCL compiler white-space problems

I'm trying to get started with OpenCL but came across weird behavior of the OpenCL compiler with respect to white-space and can't seem to find any documentation about that.
C-style single-line comments (// foo) immediately cause a meaningless build error: At end of source: error: expected a "}". Multi-line comments (/* bar */) seem to work fine.
Line breaks seem to get stripped without adding whitespace which can cause errors. This example will not compile because of that:
__kernel
void TestKernel() {}
line 1: error: identifier "__kernelvoid" is undefined
This may totally depend on my machine and/or configuration but can somebody confirm that these things should not be this way?
I am using OpenCL via Cloo from .net/C#. The driver is from AMD OpenCL 2.0 AMD-APP (1642.5)
I think I figured it out. I was doing this:
var program = new ComputeProgram(context, File.ReadAllLines(filename));
File.ReadAllLines() returns an array of strings without the line-break characters which is the root of the errors I was getting.
Using File.ReadAllTest() instead fixed all the problems:
var program = new ComputeProgram(context, File.ReadAllText(filename));
But in my opinion some of the blame goes to either Cloo or the OpenCL API for accepting a string array but just concatenating it together..

Getting values from pro files in Qt

I am using Qt 4.5 in Windows XP. My pro file has the variable VERSION = 1.0. Now i need to read this variable and get its value (1.0) from the source code. So that I don't have to maintain another variable for version inside my source code. I just read from the pro file and update it. So that the value remains consistent all over my project. Is it possible? Any pointers regarding this are welcome..
Use somethings like this:
DEFINES += VERSION=\\\"$$VERSION\\\"
This will define a macro that you can use in C source code. Get rid of the backslashes and quotes if you want a number, not a string.
I'll elaborate on this a bit.
In the YourApp.pro:
VERSION = 0.0.0.1
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
In the main.cpp:
#include <QApplication>
QCoreApplication::setApplicationVersion(QString(APP_VERSION));
Wherever else in your sources, e.g. in the imaginary controller.cpp:
#include <QApplication>
QString yourAppVersion = QCoreApplication::applicationVersion();
somehow, when I tried qDebug() << QString(APP_VERSION); in a class.cpp not in main.cpp. has an error "C2065" APP_VERSION: undeclared identifier". but when I tried in main.cpp that worked.

Resources