I accidently changed this file in visual studio 2010
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h
I modified arround here:
1082 extern "C++" // templates cannot be declared to have 'C' linkage
1083 template <typedef T, size_t N>
1084 char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];
1085
1086 #define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
If anyone has the same version of this file, could you please send me the good code for this section?
Thanks in advance
Just found the source somewhere else. The problem is
template <typedef T, size_t N>
should be template
template <typename T, size_t N>
Related
I want to store three arbitrary ints inside a std::vector without defining a struct/class. So I went for std::tuple<>:
std::vector<std::tuple<unsigned int, unsigned int, unsigned int>
Using MS VS 2013, it leads to the following error:
>c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(1628): error C2036: 'std::tuple<unsigned int,unsigned int,unsigned int> *' : unknown size
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(1622) : while compiling class template member function 'void std::vector<std::tuple<unsigned int,unsigned int,unsigned int>,std::allocator<_Ty>>::_Tidy(void)'
1> with
1> [
1> _Ty=std::tuple<unsigned int,unsigned int,unsigned int>
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(945) : see reference to function template instantiation 'void std::vector<std::tuple<unsigned int,unsigned int,unsigned int>,std::allocator<_Ty>>::_Tidy(void)' being compiled
1> with
1> [
1> _Ty=std::tuple<unsigned int,unsigned int,unsigned int>
1> ]
1> d:\projects\gl33\src\nvf.cpp(39) : see reference to class template instantiation 'std::vector<std::tuple<unsigned int,unsigned int,unsigned int>,std::allocator<_Ty>>' being compiled
1> with
1> [
1> _Ty=std::tuple<unsigned int,unsigned int,unsigned int>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =======
Is this due to limitations in the MSVS2013 compiler? Or am I doing something wrong?
A class type is known (its name is known) but its size is unknown if the type has only been forward-declared, but not defined. E.g.
struct X;
sizeof(X) // error: X is incomplete
The size of a type is important for pointer arithmetic, which is another hint when looking at the compiler error (which mentions a pointer to tuple).
MSDN provides the following example for C2036:
struct A* pA;
int main() {
pA++; // C2036, size of A not known
((char*&)pA)++; // OK, if sizeof(A) == sizeof(char)
}
Where the struct A* pa implicitly forward-declares struct A.
Such a situation can happen with headers of the Standard Library when you don't include all required headers yourself. There are interdependencies between the types in the Standard Library. If a Standard Library header requires only a forward-declaration of tuple, it won't include the heavyweight tuple header itself in an effort to reduce compilation times.
I could reproduce the issue in the OP by including only <vector> but not <tuple>. Solution: manually include all headers you need types from - when using vector<tuple<..>>, include <tuple> (as well as <vector>). In general, including a header guarantees the availability of a certain set of types. To maximize portability, always make sure the headers you've included guarantee that you can use all the types in your program(*).
(*) More specifically, you should make sure that you have a definition for all types your program needs a definition for. Standard Library containers require their value types to be complete (at least at the point where the class template is instantiated). Hence, if your program requires a definition of vector<tuple<unsigned, unsigned>>, it also requires a definition of tuple<unsigned, unsigned>.
One of the answers in SO states that we cannot bind a non const l-value reference to an r-value. This is a sample code.
#include <iostream>
using namespace std;
struct Position2D
{
float m_x;
float m_y;
Position2D(float x, float y) : m_x(x), m_y(y)
{
}
};
int main()
{
Position2D& p2 = Position2D(2, 2); // this is the line which has the problem.
Position2D&& p3 = Position2D(2, 2);
return 0;
}
The problem is Visual Studio 2013 compiler compiles above mentioned code segment without any error. But online c++11 compiler shows an error as the link which included in SO answer describes. Who is correct? Is there any problem in Visual Studio 2013 C++ compiler with new C++11 standards?
I'm experimenting with C++11 (I've used old C++ so far) and I wrote the following code:
#include <iostream>
#include <vector>
#include <type_traits>
using namespace std;
constexpr bool all_true(){
return true;
}
template <typename Head, typename... Tail>
constexpr bool all_true(Head head, Tail... tail){
static_assert( is_convertible<bool, Head>::value, "all_true arguments must be convertible to bool!");
return static_cast<bool>(head) && all_true(tail...);
}
template<typename T, typename... Args>
void print_as(Args... args){
static_assert( all_true(is_convertible<T,Args>::value...), "all arguments must be convertible to the specified type!");
vector<T> v {static_cast<T>(args)...};
for(T i : v) cout << i << endl;
}
int main(){
print_as<bool>(1, 2, 0, 4.1);
}
The code compiles and runs as expected (I used gcc 4.6). I would like to aks the following questions:
I initialized a std::vector with an expanded parameter pack ( vector v {static_cast(args)...}; ). Is this correct C++11? I haven't found this feature explained anywhere.
I don't like too much the declaration of all_true because I know the type but I use templates. Is it possible to use something similar to the following?
constexpr bool all_true(bool head, bool... tail){...} // This code doesn't compile
Thanks!
Yes, it is possible to use pack expansions inside initialiser lists. C++11 [temp.variadic]ยง4 allows this:
... Pack expansions can occur in the following contexts:
...
In an initializer-list (8.5); the pattern is an initializer-clause.
No, there's no way to make a non-template typesafe variadic function. What you have is OK. There was a question about this recently.
Consider the code:
#include <functional>
#include <vector>
#include <stdint.h>
class CFileOperationWatcher
{
public:
CFileOperationWatcher() {}
virtual void onProgressChanged(uint64_t sizeProcessed, uint64_t totalSize, size_t numFilesProcessed, size_t totalNumFiles, uint64_t currentFileSizeProcessed, uint64_t currentFileSize) {}
virtual ~CFileOperationWatcher() {}
void onProgressChangedCallback(uint64_t sizeProcessed, uint64_t totalSize, size_t numFilesProcessed, size_t totalNumFiles, uint64_t currentFileSizeProcessed, uint64_t currentFileSize) {
_callbacks.emplace_back(std::bind(&CFileOperationWatcher::onProgressChanged, this, sizeProcessed, totalSize, numFilesProcessed, totalNumFiles, currentFileSizeProcessed, currentFileSize));
}
protected:
std::vector<std::function<void ()> > _callbacks;
};
int main(int argc, char *argv[])
{
CFileOperationWatcher w;
w.onProgressChangedCallback(0,0,0,0,0,0);
}
I'm getting an error C2780 in Visual Studio 2012. Looks like there's no std::bind definition that can take that many arguments. But isn't it supposed to use variadic templates and accept any number of args?
MSVC++ 2012 has fake variadic templates that rely on macro machinery. By default, they only work for up to 5 parameters. If you need more, you can use _VARIADIC_MAX to up it as high as 10 parameters.
Here's a similar question.
VC++ added variadic templates in the 2013 version.
This compiles fine with clang (3.3), so it must be a compiler bug with VS2012.
And yes, you're correct: std::bind() is a variadic template (C++11), see also http://en.cppreference.com/w/cpp/utility/functional/bind
Visual Studio 2012 has no support for variadic templates. Visual Studio 2013 will on the other hand according to this.
I have compiled my cuda project using visual studio 2010. I have countered an error stated:
student_func.cu(65): error C2059: syntax error : '<'
The line where error occurs is when the kernel function is called:
rgba_to_greyscale<<< gridSize, blockSize >>>(d_rgbaImage, d_greyImage, numRows, numCols);
and here is the code for student_func.cu:
#include "reference_calc.cpp"
#include "utils.h"
#include <stdio.h>
__global__
void rgba_to_greyscale(const uchar4* const rgbaImage,
unsigned char* const greyImage,
int numRows, int numCols)
{
}
void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, uchar4 * const d_rgbaImage,
unsigned char* const d_greyImage, size_t numRows, size_t numCols)
{
//You must fill in the correct sizes for the blockSize and gridSize
//currently only one block with one thread is being launched
const dim3 blockSize(1, 1, 1); //TODO
const dim3 gridSize( 1, 1, 1); //TODO
rgba_to_greyscale<<< gridSize, blockSize >>>(d_rgbaImage, d_greyImage, numRows, numCols);
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
}
Please, have first a look at this guide on how to integrate CUDA in a Visual Studio C++ project.
Also, you should organize the code so that:
.h, .cpp, .c, .hpp files should not contain CUDA code (like __device__ functions and the kernel call in your case). However, in these files you can call CUDA APIs (for example, cudaMalloc, cudaMemcpy, etc.). These files are compiled by a compiler other than NVCC.
.cuh, .cu files should contain the CUDA code. These files are compiled by NVCC.
As an example, suppose to have a GPU-based FDTD code. I usually do the following (Visual Studio 2010).
main.cpp file, including CPU-GPU memory transfers;
FDTD.cu, including an extern "C" void E_update(...) function which contains the kernel <<< >>> call;
main.h file, including the extern "C" void E_update(...) prototype;
FDTD.cuh, including the __global__ void E_update_kernel(...) function.