'Correct' unsigned integer comparison

So, we all know the C/C++ signed/unsigned comparison rules where -1 > 2u == true, and I have a situation where I want to implement 'correct' comparisons efficiently. My question is, which is more efficient with considerations to as many architect...
more »

2017-05-19 13:05 (7) Answers

I know struct is a class but the code says No

I was trying to convince a friend that struct is just a class in the modern C++. After a lot of arguing and resource exchange (including some SO Q&A), I came into an idea to prove it through code, so I wrote: class A {}; struct B {}; int main()...
more »

2017-05-18 22:05 (3) Answers

Difference extern"C" vs extern

Is there a difference whether I use the extern "C" specifier for the entire header, or specify extern for every function? As far as I know, there is none, since only functions and variables can be linked externally, so when I use the extern specifie...
more »

2017-05-18 21:05 (2) Answers

Dynamically create a function and get a pointer

I am using Arduino and motor encoders to track the rotations of a motor. To do this, I am using interrupts on the Arduino. I can create a function, an ISR, that will be executed by the processor whenever the signal changes on a pin. That Interrupt/IS...
more »

2017-05-18 17:05 (3) Answers

Iterate over array of objects from txt file

I have file with records separated by comas: cities.txt: 1,NYC 2,ABQ ... I would like to iterate over each row: ids and names. I have created the code: #include <iostream> #include <string> using namespace std; class City { int ...
more »

2017-05-18 10:05 (2) Answers

Strange error in c++ class construction

I have recently started learning c++ and I am now trying to make a simple vector class as an exercise. But somehow my code doesn't seem to work. #include <iostream> #include <cmath> class Vec2 { public: float x1; float x2; Ve...
more »

2017-05-17 11:05 (4) Answers

AVX 4-bit integers

I need to perform the following operation: w[i] = scale * v[i] + point scale and point are fixed, whereas v[] is a vector of 4-bit integers. I need to compute w[] for the arbitrary input vector v[] and I want to speed up the process using AVX in...
more »

2017-05-16 22:05 (1) Answers

how to specify '-o3' gcc flag in build.gradle

in my build.gradle, I set to use gcc: arguments '-DANDROID_TOOLCHAIN=gcc' in CMakeList, below script works: if (${ANDROID_ABI} STREQUAL "armeabi-v7a") # make a list of neon files and add neon compiling flags to them set(neon_SRCS src/main/cpp/t...
more »

2017-05-16 08:05 (1) Answers

Why does sequence iteration work in C macro?

When writing C macro, there is a trick called "sequence iteration". It looks like as follow: #define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__) #define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ #define FUNCTION(name) void name(); #define FUNCTION_TABLE(...
more »

2017-05-16 08:05 (2) Answers

Share OpenCV C++ Object with Python

Scenario: A C++ program process capture a image using OpenCV. Another process, using Python and OpenCV have a shared memory area (with mmap) with the first program. Problem: How do I create in a Python process, a reference to the same image that a...
more »

2017-05-16 02:05 (0) Answers

C++ library header not found

I am OS X user and I've recently installed "cppunit" library using brew. When I try to compile "test.cpp" file using TestCase.h header the error occurs: > test.cpp:3:10: fatal error: 'TestCase.h' file not found > #include "TestCase.h" I...
more »

2017-05-15 22:05 (1) Answers

Empty std::string in static method initialiser

I am using a static method to initialise the const fields of a class. The static method uses some const variables that are stored in a separate header file. Primitive types are correctly being passed to the static method, but the std::strings are bei...
more »

2017-05-15 22:05 (1) Answers

const annotation for Haskell FFI exports

I am exposing a Haskell function to C/C++ as foreign export ccall foo :: Ptr CInt -> CInt -> IO CInt foo ptr len = do list <- peekArray (fromIntegral len) ptr -- run calculation based on list entries return result The signature of ...
more »

2017-05-15 10:05 (1) Answers

Why is a function not an object?

I read in the standards n4296 (Draft) § 1.8 page 7: An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. —end note ] I spent some days on the ...
more »

2017-05-15 05:05 (3) Answers

Make a class that cannot be instantiated?

Suppose that I have a class Bar. I want to use Bar uniquely as a base class, e.g.: class Foo : public Bar I want to disallow Bar from being able to be instantiated. In other words, I want Bar object; to be an error. Is this possible to do? ...
more »

2017-05-15 00:05 (1) Answers

Pari compatibility with C++ classes

I'm writing a program using Pari and used classes to code conveniently, but it seems that Pari is not compatible with C++ classes. I made a class that had a GEN variable and initialized it using the constructor. Every time I try to access that variab...
more »

2017-05-13 21:05 (0) Answers