C++ : extern variable inside namespace and printf vs cout -
i have little problem printf , don't know why !
=>kernel.h
#ifndef kernel_h #define kernel_h namespace kernel { extern const double h; } #endif // kernel_h
=>kernel.cpp
#include <kernel.h> namespace kernel { const double kernel::h=85.0; }
=>main.cpp
#include "kernel.h" #include <iostream> //#include <cstdio>//with cstdio, same problem ! int main(int argc, char *argv[]) { using namespace kernel; double = h; printf("printf %d\n",a); std::cout<<"std::cout " << << std::endl; printf("printf h %d\n",h); printf("printf kernel::h %d\n",kernel::h); std::cout << "std::cout h " << h << std::endl; return 0; }
and output on console :
printf 0 std::cout 85 printf h 0 printf kernel::h 0 std::cout h 85
why printf doesn't work? because c function ?
thanks
that because printing integer
. try %lg
or %lf
printf("printf kernel::h %lg\n",kernel::h);
if turn on warnings compiler have told problem. -wformat
or use std::cout
, won't have kind of problems
std::cout << kernel::h;
Comments
Post a Comment