Variable forward declaration problem

The following example code predeclare a foo variable, use it and then set it.

[font=“Courier”]int foo[2];

void test() {
foo[0] = 5;
}

int foo[2] = { 10, 11 };[/font]

Its compile fine with gcc, but nvcc return the following error:

[font=“Courier”]nvcc -o obj/release/simple.cu_o -c simple.cu -I. -I/usr/local/share/cuda-64/include -I…/…/common/inc -DUNIX -O3 -v
# _SPACE_= # HERE=/usr/local/share/cuda-64/bin
# TOP=/usr/local/share/cuda-64/bin/.. # LD_LIBRARY_PATH=/usr/local/share/cuda-64/bin/…/lib:/usr/local/share/cuda-64/bin/…/extools/lib:
# PATH=/usr/local/share/cuda-64/bin/../open64/bin:/usr/local/share/cuda-64/bin/../bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/share/cuda-64/bin # INCLUDES="-I/usr/local/share/cuda-64/bin/…/include" “-I/usr/local/share/cuda-64/bin/…/include/cudart”
# LIBRARIES= "-L/usr/local/share/cuda-64/bin/../lib" -lcuda -lcudart # PTXAS_FLAGS=
# OPENCC_FLAGS= # gcc -E -x c++ -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS “-I/usr/local/share/cuda-64/bin/…/include” “-I/usr/local/share/cuda-64/bin/…/include/cudart” -I. -D__CUDACC__ -C -O3 -I"." -I"/usr/local/share/cuda-64/include" -I"…/…/common/inc" -D"UNIX" -include “cuda_runtime.h” -m64 -o “/tmp/tmpxft_00002ce3_00000000-3.ii” “simpleCUFFT.cu”
#$ cudafe --m64 “-I/usr/local/share/cuda-64/bin/…/include” “-I/usr/local/share/cuda-64/bin/…/include/cudart” -I. --gen_c_file_name “/tmp/tmpxft_00002ce3_00000000-0.c” --gen_device_file_name “/tmp/tmpxft_00002ce3_00000000-0.gpu” --include_file_name /tmp/tmpxft_00002ce3_00000000-2.c --diag_error=host_device_limited_call --no_exceptions -tused -I"." -I"/usr/local/share/cuda-64/include" -I"…/…/common/inc" -D"UNIX" “/tmp/tmpxft_00002ce3_00000000-3.ii”
“simple.cu”, line 7: error: variable “foo” has already been defined
int foo[2] = { 10, 11 };
^

1 error detected in the compilation of “/tmp/tmpxft_00002ce3_00000000-3.ii”.

–error 0x200 --[/font]

Is it an compiler error or cuda dont want support forwarding declaration for variables? But it’s works fine for functions :blink: