Improving supplementary code editing

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.
Post Reply
mnfisher
Valued Contributor
Posts: 1674
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 145 times
Been thanked: 779 times

Improving supplementary code editing

Post by mnfisher »

Supplementary code is a useful feature if you need to add a little more C to your flowchart than is comfortable in a code block.

However - editing it is a bit more awkward than a normal Flowcode macro - for example - you can't open another macro / view variables etc, it's a bit clunky to get to (project options - supplementary code) and get out of - save, modify too - and the editor has none of the advantages of a C editor such as syntax checking.

There is an easy solution to this - that I had used before in passing - but recently needing to work a fair bit with some code - and it really makes life easier.

In the supplementary code "Definitions and function declarations:" do:

Code: Select all

#include <my_header.h>
and in the "Function implementations:" section do:

Code: Select all

#include <my_functions.c>
Create and edit the files my_header.h and my_functions.c (names can be changed to suit of course) - in your favourite editor (I use notepad++) - and then save any changes before compilation.

The files need to be in the compilers search path - and as I am currently using the esp32 I created a new directory 'include' in the project/main folder and added this to the search path by adding the folder to CMakeLists.txt (in main)

Code: Select all

idf_component_register(SRCS "esp-project.c"
                    INCLUDE_DIRS "" "include")
The technique will vary depending on target device however.

Martin

Steve-Matrix
Matrix Staff
Posts: 1579
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 221 times
Been thanked: 369 times

Re: Improving supplementary code editing

Post by Steve-Matrix »

Thanks, Martin. I've done that in the past and is useful when you have supplementary code that is being worked upon.

To add to your post, the "#include" statements are relative. This means if the Flowcode project moves to a different folder on your PC, then the file will not be found. To avoid this issue, an absolute reference could be used instead, eg:

Code: Select all

#include "C:\my_working_folder\my_header.h"
Note a double "\\" (or even a single "/") may be needed instead of a single "\" because that is used as an escape character in strings (e.g. "\n" is the newline character). The behaviour of these slash characters in #include statements in undefined in old C standards, so you'd need to confirm what works with the C compiler being used by Flowcode.

Furthermore, if the Flowcode project file is opened on another PC (e.g. the project is shared with someone else or you want to use it on a different PC), then the external files will also need to be copied over into the appropriate place on the other PC.

One of the benefits of having actual code within supplementary code (as opposed to links to external files) is the code is saved inside the project file and will move wherever the project file goes. So once the external files have become 'stable', it would be a good idea to replace the "#include" statements with the actual code.

Post Reply