[Bug Report] Simple but weird

I have compiling error for the following code.

<weird.cu>

unsigned char a = 0x8A;
int main(void) {return 0;}

Platform: Windows 7, 64 bit
CUDA Toolkit: 7.0
Visual Studio: 2012

The error will disappear if I change:

  1. CUDA Toolkit: from 7.0 to 6.5
  2. Or the value in the above code: from 0x8A to 0x7A

Any ideas for this issue?

On a developer forum you should have provided the exact compilation error message in your question.

Does it work when assigning an unsigned immediate value instead of a signed one to your unsigned char variable by appending a ‘u’-suffix?

unsigned char a = 0x8Au;

More observations:

  1. unsigned char a = 0x8Au; //NG
  2. CUDA7.5RC //NG
1>------ Build started: Project: vectorAdd, Configuration: Release x64 ------
1>  Compiling CUDA source file weird.cu...
1>  
1>  C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5

1>------ Build started: Project: vectorAdd, Configuration: Release x64 ------
1> Compiling CUDA source file weird.cu…
1>
1> C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include" -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”
1> weird.cu
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(2): error C2001: newline in constant
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2144: syntax error : ‘int’ should be preceded by ‘)’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2143: syntax error : missing ‘;’ before ‘{’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2447: ‘{’ : missing function header (old-style formal list?)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110\BuildCustomizations\CUDA 7.5.targets(604,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include” -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include” --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”” exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

_Simple\vectorAdd>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" -gencode=arch=compute_37,code=\"sm_37,compute_37\" -gencode=arch=compute_50,code=\"sm_50,compute_50\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I./ -I../../common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\/include" -I../../common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include"     --keep-dir x64\Release -maxrregcount=0  --machine 64 --compile -cudart static -Xcompiler "/wd 4819"     -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MT " -o x64/Release/weird.cu.obj "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5

1>------ Build started: Project: vectorAdd, Configuration: Release x64 ------
1> Compiling CUDA source file weird.cu…
1>
1> C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include" -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”
1> weird.cu
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(2): error C2001: newline in constant
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2144: syntax error : ‘int’ should be preceded by ‘)’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2143: syntax error : missing ‘;’ before ‘{’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2447: ‘{’ : missing function header (old-style formal list?)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110\BuildCustomizations\CUDA 7.5.targets(604,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include” -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include” --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”” exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

_Simple\vectorAdd\weird.cu" 
1>  weird.cu
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(2): error C2001: newline in constant
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2144: syntax error : 'int' should be preceded by ')'
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2143: syntax error : missing ';' before '{'
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2447: '{' : missing function header (old-style formal list?)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110\BuildCustomizations\CUDA 7.5.targets(604,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" -gencode=arch=compute_37,code=\"sm_37,compute_37\" -gencode=arch=compute_50,code=\"sm_50,compute_50\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I./ -I../../common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\/include" -I../../common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include"     --keep-dir x64\Release -maxrregcount=0  --machine 64 --compile -cudart static -Xcompiler "/wd 4819"     -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MT " -o x64/Release/weird.cu.obj "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5

1>------ Build started: Project: vectorAdd, Configuration: Release x64 ------
1> Compiling CUDA source file weird.cu…
1>
1> C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include" -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”
1> weird.cu
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(2): error C2001: newline in constant
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2144: syntax error : ‘int’ should be preceded by ‘)’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2143: syntax error : missing ‘;’ before ‘{’
1>C:/ProgramData/NVIDIA Corporation/CUDA Samples/v7.5/0_Simple/vectorAdd/weird.cu(3): error C2447: ‘{’ : missing function header (old-style formal list?)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110\BuildCustomizations\CUDA 7.5.targets(604,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” --use-local-env --cl-version 2012 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64” -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5/include” -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include” --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -o x64/Release/weird.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\0_Simple\vectorAdd\weird.cu”” exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

_Simple\vectorAdd\weird.cu"" exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I dropped your code into the vectorAdd sample project (replacing the code that was there) on a Win 7 x64 machine with CUDA 7 and VS2013 community. I didn’t have any trouble compiling it.

Can’t reproduce it either (Win7 x64, CUDA 6.5). The only situation I am aware of that could cause this kind of error is something like

unsigned char a = \;

where the ‘’ is interpreted as the start of an escape sequence, and to get the backslash one needs to write

unsigned char a = \\;

Original report indicated the problem is not reproducible under CUDA 6.5

Perhaps the problem is reproducible in Windows in another language besides english.

Oops, missed that part of CUDA 6.5 not being broken. Other than locale, another hypotheses would be that one of the CUDA header files included by CUDA toolchain under the hood has become corrupted, leading to a parsing error on the first line of the user code.