Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: How to break code and variable declarations into manageable chunks

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Location
    Chipping Norton, UK
    Posts
    220

    Talking How to break code and variable declarations into manageable chunks

    Hi

    My backgound in writing code is that I am a hobbyist programmer self taught along time ago in VB6 and then moved to C#, a very comfortable place in comparison to C/C++ it seems. I am allowed to abuse a lot of purist programming principles it would seem in C#, not as much as VB allowed, but a lot it seems when compared to C/C++. One step at a time I suppose.

    I am working in the Arduino environment for the project I am currently working on and I am using a tool called Visual Micro (http://www.visualmicro.com/) to allow me to develop in the environment I know best, Visual Studio 2010. I highly recommend this to anyone who uses Visual Studio day to day as you get many of the advantages of intellisense single button compile and single button compile and upload straight from the IDE. It is great, and no I am not affiliated in any way, I just think it is a great tool.

    What I would like to do is break my code into manageable chunks as I am finding it harder and harder to navigate as it grows.

    I find it very frustrating not being able/ not knowing how to create collapsible regions that I use extensively in C# programming. I have frigged it using a preprocessor block "#if 1 . . . #endif" to wrap my ever growing variable declaration block. Fortunately at least the methods collapse.

    What I would like to do is split my code into manageable files. I have nearly 4000 lines of code now and was wondering what is the best way to approach this. I have had a look at creating libraries but this does not fit well at this time.

    Do I just create seperate xxx.c, yyy.c, zzz.c, etc files in my project folder and allow the compiler to include them?

    Sorry for those that find the question tedious, we all have to learn.

    I welcome any constructive advice and will try to absorb any numpty abuse

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    When using Arduino, you can use as many files as you like. All the .ino and .pde files are concatenated into a single file for the compiler. Usually it's easy to just open a new tab in the Arduino editor and cut-and-paste chunks of code to other tabs (which by default will be .ino files).

    All the .c and .cpp files are compiled separately. Generally, you put any normal Arduino code into a .cpp file, but you'll need to declare functions in a .h file and include that .h in all files that use the function.

    I have not personally used Visual Micro. I really don't use Windows much, other than testing... I primarily use Linux and I even build Windows programs using a cross compiler on Linux. So I can't help with Visual Studio or Visual Micro. If it compiles things differently than Arduino does, you might need to use a different strategy?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •