Wednesday, August 28, 2019

Problem with mixing C++ and C code

In a C++ project that also contained legacy C files, I started to get the error "C2664 ...cannot convert argument 3 from void * to const_locale_t". The argument in question was NULL. Changing the include order by including the legacy header after stdio.h solved the problem but I wanted to understand the root problem to avaiod unnecessary technical debt.

One of the C headers contained #define NULL ((void *)0) which is standard for C but not for C++. Normally NULL is defined inside vcruntime.h (part of Visual C++). Using the legacy NULL before any code that depends on vcruntime.h, like string.h, stdio.h, caused this error. Removing the custom definition or changing it to the following solved the problem, see also my answer on StackOverflow:
Another strange error happens if you have defined fmax globally in your own C code because it also exists in cmath. The strange error will be C2039 'fmax': is not a member of 'global namespace'. Removing or renaming your own custom definition will solve the problem.

Monday, August 19, 2019

How to learn

Below are my learning steps with bitcoin/blockchain as an example:
  1. Heard the keyword bitcoin and got curious, read a few webpages, understood very little. Wondered what the use of mining was.
  2. Finally got the gist of it by watching But how does bitcoin actually work.
  3. To undertand blockchain in more detail, started implementing a simple version of blockchain (in progress)
  4. Review original paper, be able to follow research on the subject.
  5. Review original source code.
  6. Make improvements.
I use similar steps to learn AI. Last year I worked with an intern, this year a second intern is working on training openCV.

In general:
  1. Understand the general concept by watching short (~15min) videos.
  2. Know enough to define work for novices/interns.
  3. Be able to use existing tools.
  4. Be able to implement basic version.
  5. Follow literature.
  6. Make improvements.
This strategy makes sure that I always have something useful even when I do not reach the final step.

Thursday, August 01, 2019

Processing directory list in a Windows batch file

Handle a specific directory in current folder differently from other folders:
Note that if you only wanted to check if a directory existed, a simple EXIST would suffice.

Bonus: If you want to set the result of a command to a variable, you can use this. Note that you have to enclose the command with ` `, not ' '. This reminds me of my double quote problem in Visual Studio...