logging - Simple c++ program gets compilation errors -


when i'm trying compile code, shows error:

main.cpp:19:3: error: invalid operands of types 'void' , 'int' binary 'operator!=' 

this file:

#include <iostream> #include <cstdio> using namespace std; #define $ debug #define debug 1 #define _(out) do{  std::cout << __file__ << ":" << __line__ \                        << " " << out << '\n';}while(0) #define _(out) printf(out); int main(){  #ifdef local_project     #define debug 0 #endif      $ && ({         _("eeeeewe");     });//line 19      return 0; } 

$ simple name of debug, in runtime it's 0 or 1.

the compilation error source file. how rid of , compile?

there things you're doing here inadvisable, , illegal. gave upvote @ least alerting me gcc extension hadn't seen:

#include <iostream>  int main() {     int x = ({std::cout << "i'm surprised prints "; 10 + 20;});     std::cout << x << "\n"; } 

that indeed output on ideone i'm surprised prints 30, under c++14 settings. on coliru, though get:

main.cpp:4:17: warning: iso c++ forbids braced-groups within expressions [-wpedantic]

yet we've had our learning moment together, avoid non-standard extensions. partly because people on stackoverflow yell @ you. reasons life hard enough trying find terra firma in language development, education , usage when stick subset has been agreed upon , vetted large number of people thought through issues.

(the "language feature 1 guy added time project" bad idea--for definition of "that 1 guy" or "that project".)

also, that--being used--probably has kinds of lack of attention in optimizer getting expression out. means @ best it's slower other ways, , @ worst has random bugs.


moving on:

  • the use of $ in identifier names is apparently "implementation-defined behavior". meaning there's nothing in spec disallowing it...but nothing saying compiler has implement either. it's not want inventing new creative uses of, , using if you're stuck in situation bridging old code on vax or something.

  • on other hand, you can't name global variables or macros starting underscore. reserved compiler implementations use themselves. (if read you'll see other unusual nuances, such can't have identifiers beginning underscore , followed capital letter in scope, although if letter lowercase can define them locally. people use member variables have careful follow rule.)

  • it's possible use printf purposes of compatibility...because of explicit design enable taking old c programs , upgrade them c++. shouldn't writing new constructs or code using it, , if want basic philosophy on why read short paper learning standard c++ new language. it's old paper in own right, it's bjarne stroustrup , works through particular point pretty well.

yet "biggest" issue of why approach wrong there more reliable ways of doing trying grab textual swaths of code macro. many topics study on that, such use of lambdas in c++11. more should focus on appears desire here, subject area of logging. quick search tag intersection advice on that:

search query [c++] [logging] __file__

how rid of , compile?

introduce intermediate steps process.

  1. get rid of this...(code!)
  2. read through links i've provided.
  3. look @ approaches used achieve goal , assess or don't them.
  4. write new code uses better practices, or borrow others.
  5. ...and compile. :-)

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -