{"action":"opened","issue":{"url":"https://api.github.com/repos/mysensors/Arduino/issues/393","repository_url":"https://api.github.com/repos/mysensors/Arduino","labels_url":"https://api.github.com/repos/mysensors/Arduino/issues/393/labels{/name}","comments_url":"https://api.github.com/repos/mysensors/Arduino/issues/393/comments","events_url":"https://api.github.com/repos/mysensors/Arduino/issues/393/events","html_url":"https://github.com/mysensors/Arduino/issues/393","id":132879406,"number":393,"title":"Problem with MySensor.h including .cpp files","user":{"login":"TD22057","id":1421685,"avatar_url":"https://avatars.githubusercontent.com/u/1421685?v=3","gravatar_id":"","url":"https://api.github.com/users/TD22057","html_url":"https://github.com/TD22057","followers_url":"https://api.github.com/users/TD22057/followers","following_url":"https://api.github.com/users/TD22057/following{/other_user}","gists_url":"https://api.github.com/users/TD22057/gists{/gist_id}","starred_url":"https://api.github.com/users/TD22057/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TD22057/subscriptions","organizations_url":"https://api.github.com/users/TD22057/orgs","repos_url":"https://api.github.com/users/TD22057/repos","events_url":"https://api.github.com/users/TD22057/events{/privacy}","received_events_url":"https://api.github.com/users/TD22057/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-11T03:33:33Z","updated_at":"2016-02-11T03:33:33Z","closed_at":null,"body":"I ran into compilation errors in a sketch that are due to the way that MySensor.h is written in the development branch.  That file includes a lot of .cpp code files in #include directives.  That means that every #define macro, every function, and every variable defined in those files can conflict with my own code in the sketch and potentially other libraries that I include (not sure about that one).\r\n\r\nI hit this first with a variable.  I was using a variable (_address) which is defined in the transport cpp files.  I figured this was a mistake so I added 'static' to the front of the _address variable in the transport files since that variable is only needed by the transport functions and should be private (all variables should be limited to the minimum scope they need to be used in - especially in libraries).  But that fix didn't work - because the radio cpp file is being included into my main sketch code via MySensor.h.\r\n\r\nThe I hit this problem again when I defined a variable \"TIME_OUT\" which happens to conflict with a macro definition in the RFM69.cpp file.  Again - same problem.  By including the cpp file, every single definition is being added to the same scope as the sketch.  Given the number of files being included, this is a large number of variables and macro which can have common names (f2, TIME_OUT are just a couple I found).  Given that all of these definitions are basically hidden in cpp files (which should normally be the private implementation part of a library), I don't think this working very well.  \r\n\r\nIt's not obvious to me why including cpp files in MySensor.h (or anywhere) is a good idea (I'm sure there is a reason for it of course).  IMHO, it would be a lot better to keep cpp files as separate compilation units and limit all names to the minimum scope they need for use (adding static for most, if not all variables).  Even better would be to be eliminate macros in headers whenever possible and use namespaces for all functions and global variables to avoid all name collisions.\r\n\r\nI'm willing to help out with this work if you agree that it's a good idea.  Just let me know..."}}