There are some caveats with preprocessor defines that have to be taken into account - first one that comes to my mind is the preprocessor directive is NOT a function NOR a variable, for example #define SUM_AB a + b and then later in code SUM_AB * 2. The result of this expression will be a+b*2 and the result will be different than it looks like in code.. That is why You should always include the right hand side of preprocessor define in parenthesis like this #define SUM_AB (a+b). Be careful :)
@AndreasSpiess
5 жыл бұрын
You are right. This video was not intended as a "full blown" introduction, it was more designed as a "hook" that these directives can be of use for certain problems.
@gatisozols
5 жыл бұрын
The video is perfectly fine, Andreas, everything You said there is correct!
@glenngoodale1709
5 жыл бұрын
I come here for every new video! You express excitement that myself and many others are feeling.
@AndreasSpiess
5 жыл бұрын
Thank you for your nice words!
@la6mp
5 жыл бұрын
Excellent, you explained in a crystal clear way an area I have not dared to enter on my own yet. My present projects will be put on a short hold in order to explore this way of pre-processing. Thank you!
@AndreasSpiess
5 жыл бұрын
Thank you. I thought it is useful, especially in the area of ESP32/ESP8266 which are very similar, but not the same... It is quite old knowledge, but not everybody is aware of it.
@LauwersFreddy
5 жыл бұрын
Andreas, great video! One request, when you do IDE style videos like this one. The right half of the screen is empty. Could you enlarge the font (like 150% or 200%) and use more of the screen to help us when watching on a smaller device? Thank you for making these videos.
@AndreasSpiess
5 жыл бұрын
The right part is for the output of the Serial monitor. I agree that small screens are not good for watching coding. This is why I try to avoid code in my videos as much as possible. If I enlarge the font the overview is lost and people do not know where I am. My code screen size is only 1280x720, the rest is in HD. So I enlarged it already...
@DamienWise
5 жыл бұрын
Very elegant and useful compiler tricks here, thankyou! I'm sure I've used these in the past, but the way you've presented things together here, and explained them so clearly makes me want to change the way I consider compiler optimisation and structure code. Bravo, and thankyou again.
@AndreasSpiess
5 жыл бұрын
Thank you for your nice comment!
@b0bjedump
5 жыл бұрын
You're an awesome teacher Andreas! I would pay to sit in your class!
@AndreasSpiess
5 жыл бұрын
Thank you! You can support me (via Patron) if you want ;-)
@PhG1961
5 жыл бұрын
Great video ! A refresh of things I (almost) forgot. Thnxs !
@AndreasSpiess
5 жыл бұрын
That's what I thought before I did this quickie. With the ESP8266/ESP32 I thought, it could have good usage.
@tablatronix
5 жыл бұрын
Some more tips, #warning "this is a compiler warning" is useful if you need to show something important, #ifdef is short for #if defined(), which you have to use if you want to check for more than 1 condition, #if defined(BLARGH) && defined(HUH), same for elif - else if defined(), now if someone could figure out how to define in sketch and properly check in a library, I have not been able to figure that one out.
@tablatronix
5 жыл бұрын
Oh and header/include guards ( the ifndef #define at the top of most includes ) serves to wrap the entire file so it only gets run once
@AndersJackson
5 жыл бұрын
@@tablatronix gets "included" once, not "run" once. Except for that, good addition. And yes, when using macro, NEVER add Space between name and left parenthesises, as you can do with C funktions. So always uses capital characters in macros, so users doesn't confuses them with proper functions.
@tablatronix
5 жыл бұрын
I had include and changed it, cause it was like include includes included .. lol
@sbx320
5 жыл бұрын
@@tablatronix I'd actually prefer #pragma once to old-style include guards these days. While it is not a standard thing, it is well supported by all the relevant compilers.
@AndreasSpiess
5 жыл бұрын
@tablatronix: Thanks for the additions!
@nldestinyx1440
5 жыл бұрын
There is one little statement that you forgot, but is very useful! Namely #ifndef (if not defined)
@AndreasSpiess
5 жыл бұрын
You are right.
@GRBtutorials
5 жыл бұрын
The debug levels are even easier to implement in ESP-IDF. You just use the macro ESP_LOGX(TAG, message), where X can be V (verbose), D (debug), I (info), W (warning) or E (error), from less to more important, and then define the level in menuconfig, before compiling. Also, a neat feature is that you can define the TAG for different sections of the code and be able to easily identify them.
@AndreasSpiess
5 жыл бұрын
Interesting. I wonder if we could use a similar concept with the Arduino IDE as in the newer ESP boards definitions it has also those debug variants. Maybe they are even the same?
@vanomel528
5 жыл бұрын
You totally blow my mind with using short form of "will" with relative "that" in this video name. Just use "will", "can" or "would". By the way thanks a lot for your work.
@AndreasSpiess
5 жыл бұрын
For statistics, I used: Will: 4 times That: 15 times Can: 9 times Would: 7 times ;-)
@Vasilaka
5 жыл бұрын
Thanks a lot. Seems, you was born to be a Techer!
@AndreasSpiess
5 жыл бұрын
:-)
@k5at
5 жыл бұрын
Great Video, Andreas! Using directives like that are a life (memory) saver for sure.
@AndreasSpiess
5 жыл бұрын
Thank you!
@danielhawkins3392
5 жыл бұрын
Great video. Thankyou linking the content to usueful applications.
@AndreasSpiess
5 жыл бұрын
You are welcome!
@arduinosynod1571
5 жыл бұрын
Thank You Andreas
@AndreasSpiess
5 жыл бұрын
You are welcome!
@svenpetersen1965
5 жыл бұрын
Ich finde es gut, dass Du so ein wichtiges Thema einmal ansprichst. Ich benutze die #... schon lange, sie waren mir immer sehr nützlich. Damit kann man nur ein Programm für unterschiedliche Hardware haben oder mit unterschiedlichen Logos und spart sie die Pflege unterschiedlicher Sourcecodes.
@AndreasSpiess
5 жыл бұрын
Mit dem Auftauchen des ESP32 und vieler Boardvarianten habe ich mir gedacht, dass ich das Thema wieder mal "aufwärmen" könnte. Viele "Neuankömmlinge" kennen das Konzept nicht.
@svenpetersen1965
5 жыл бұрын
Andreas Spiess Das ist super. Ich mag KZitem, wenn man etwas davon lernen kann :-)
@stuartajc8141
5 жыл бұрын
Useful tips, thanks. One slight correction. You showed this: int LED = D1; but that won't compile as D1 isn't an integer value, the error is: 'D1' was not declared in this scope
@AndreasSpiess
5 жыл бұрын
I thought the same. That’s why I tried. It compiled with ESP8266 NodeMCU 1.0 :-)
@stuartajc8141
5 жыл бұрын
Ahh, I see. I was compiling for an ESP32. Thanks, I have learned several things today :-)
@akj7
5 жыл бұрын
For the arduino, int variable = D2 or int variable = A2 means digital/analog.
@pfeerick
5 жыл бұрын
D1 isn't an integer value, but depending on what board you are compiling it for, it may have a pins_arduino.h definition, i.e. for NodeMCU it is "static const uint8_t D1 = 5;" whereas it is "static const uint8_t D1 = 1;" for the Wemos D1, and for others it may have no definition, hence it will fail. It's all part of the precompile 'black magic' that occurs when you hit the compile button ;)
@avejst
5 жыл бұрын
Nice, thanks for sharing 👍😀 Interesting update 😀👍
@AndreasSpiess
5 жыл бұрын
Thank you! I try to focus the Thursday videos more on tips an tricks. They should also be shorter than the Sunday videos (Quickie)
@akshaygupta3624
5 жыл бұрын
You are so great at making tutorial videos
@AndreasSpiess
5 жыл бұрын
Thank you!
@birnodin
5 жыл бұрын
One more: Want to comment out many lines of code and not think about if comments like // oder /* are already used in the code? Write #if 0 ... ... #endif and all is ok. And for C++ programmers: Better use the C++ syntax than #typedef and other preprocessor macros. Remember the compiler will only see the lines AFTER the preprocessor has run. So the compiler could not do type checking and other benefits from C++. You may even consider to write "const int A = 3" than "#define A 3".
@AndreasSpiess
5 жыл бұрын
Thank you for your tips!
@toastrecon
5 жыл бұрын
Awesome! Great information.
@AndreasSpiess
5 жыл бұрын
Thank you!
@deangreenhough3479
5 жыл бұрын
Another great video Andreas👍 really well pulled together and explained. Thank you 🏴🙏
@AndreasSpiess
5 жыл бұрын
Thank you! It was just a "Quickie" ;-)
@jackdaniels8898
5 жыл бұрын
Excellent as always. Thank you!
@AndreasSpiess
5 жыл бұрын
You are welcome!
@sethrd999
5 жыл бұрын
Great video Andreas covering more C/C++ ism's with defines. I know alot of people frown on these things but if you look at FreeRTOS its used quite a bit aswell as other RTOS implementations out there, so this is a great guide on how and why with complete illustration.
@AndreasSpiess
5 жыл бұрын
Thank you for your feedback!
@ralfschurer4187
5 жыл бұрын
As always, an excellent explanation! I simply love your channel .....
@AndreasSpiess
5 жыл бұрын
Thank you!
@user-hq8cw6ro8f
5 жыл бұрын
Hello Andreas, many thanks for your soldering tips @ IoT meetup in Basel. Today I did a test soldering on some of the discussed boards and I thing I managed it quite good. It's time for doing a check now and see if there is any connection error. I wish you a nice weekend and maybe see you next time. Best regards Matt
@AndreasSpiess
5 жыл бұрын
Glad to read that it works now better. Some practice and you will be a master ;-)I will be at the next Meetup, for sure....
@a_boy_can_dream
Жыл бұрын
You're awesome. Was just asking myself the other day what that #define was and why I should use it over int x = y. Great video!
@AndreasSpiess
Жыл бұрын
Glad you liked it!
@mrverdant13
5 жыл бұрын
Great video, Andreas!! Useful info!!
@AndreasSpiess
5 жыл бұрын
Thank you!
@Ernzt8
5 жыл бұрын
Thank you so much for this! Makes coding a lot clearer :)
@AndreasSpiess
5 жыл бұрын
You are welcome!
@RETRODISTORT
5 жыл бұрын
Great video! So many interesting ideas. Keep it up :)
@AndreasSpiess
5 жыл бұрын
Thank you!
@ahmedgerges3955
5 жыл бұрын
Thanks for the info..it's real good
@AndreasSpiess
5 жыл бұрын
You are welcome!
@PerchEagle
5 жыл бұрын
Yes, also with a combination of typedef structs and unions where unions have a use for defined values and structs for storing certain values that are connected. I encounter these levels of programming with the libraries I download from the web. But I don't use them more intensively. I use direct functions with parameters if needed and some defines. My comment is mainly on C programming, maybe it's not so relative but that's my current programming work, I haven't started C++ with building classes and get the Arduino experience. It should be interesting, but also C also has a wide expand world, Linux is built on C! That's why I didn't move to C++.
@AndreasSpiess
5 жыл бұрын
Structs are also a nice thing most Arduino programmers do not know. The same with enum. Maybe I do a quickie for these, too in the future...
@PerchEagle
5 жыл бұрын
@@AndreasSpiess But they are for C right? If you like C++ maybe you can do a tutorial about how to do a C++ class it would be amazing I'm really looking to get into C++. You can investigate if it's worth doing some programming with C++ for microcontrollers. Even with all thoughts about C++ I haven't yet started to implement structs and enums in C libraries.
@AndreasSpiess
5 жыл бұрын
Arduino IDE is C++. I do not know C.
@PerchEagle
5 жыл бұрын
@@AndreasSpiess C is very similar to C++, the directives you explained in the video are derived from C :)
@YigalBZ
5 жыл бұрын
Few issues come to my mind with #define: it is hard to debug compiler errors and mistake because we have no access to the post processing output file (I wish there was a way to see it). For example, the wrong semicolon (;) in the following statement ( #define motor_pin 13; ) . It can take some time before noticing the stupid mistake - I often add ";" because I am used to. Perhaps Const int can be a better use. For start, it is not taking more memory (unless you use it as a pointer later on), and it is also making sure that the defined variable is int. #define can cause other variable sizes to be created later on. However, const int will not work with analog pins because they use the "A" character (e.g. pin A4).
@AndreasSpiess
5 жыл бұрын
As always in life, there are pros and cons. So each of us probably has some tricks. In Arduino, most examples use #defines.
@HobbyelektronikerCh
5 жыл бұрын
Das mit den Debug - Levels ist eine gute Idee. Ich werde es ebenfalls einbauen.
@AndersJackson
5 жыл бұрын
Read the original C programming book by Richie. I think it is translated into German too.
@AndreasSpiess
5 жыл бұрын
Ich habs auch irgendwo gefunnden (vor Jahren). Mit dem Ankommen des ESP32 dachte ich, dieses Thema gehört mal wieder auf den Tisch, weil es doch einige Probleme löst.
@tengelgeer
5 жыл бұрын
Do note C++ has better alternatives for pre-processor directives in most cases. For pin definitions we have the safe const byte alternative which give wayyyy nicer errors if you made a mistake. And even for debug you can use const and regular if's. The compiler is smart enough to leave unused parts out. So for point 3 I would prefer a const variable. Granted, PPD make it easy for a lot of types and in a library the debugging is already "done" on the PPD. Two big shortcomings of the linked library, you can not give a second parameter to print. So you're stuck to decimal and 2 decimals on float. Second, you can only use Serial as debug. That's why I once made github.com/septillion-git/DebugLib But out of the box it does not support debug levels.
@AndreasSpiess
5 жыл бұрын
There were discussions whether the compiler used in the Arduino IDE removes the const variables. But you are, of course right for the newer compilers. Common practice in the Arduino environment is still to use defines. I will have a look at your debug library. I am sure I can learn something from somebody who really knows C++
@electronic7979
5 жыл бұрын
Useful video 👍 Excellent 👍
@AndreasSpiess
5 жыл бұрын
:-)
@milenedejong1400
5 жыл бұрын
nice video mr spiess ..
@AndreasSpiess
5 жыл бұрын
Thank you!
@benni5541
5 жыл бұрын
I rather like to use normal variables and if statements and an very early readout of the powerregisters to set the debuglevel. This way my projects are silent untill i rest them with the reset button. For Atmel mcus there exist bits for external reset,brown out programmer reset,watchdog etc.
@AndersJackson
5 жыл бұрын
That is also a way of doing this, BUT, it isn't the same. You will still have the debug code compiled into the program even when you not uses it. And you will have "dead" code in your program. The convention in C programs is to use macro directives for constants and comment in/out code depending on what you want to have in your program.
@AndreasSpiess
5 жыл бұрын
I am not sure if your method works for libraries or code which is understood only by the compiler for one processor. ESP32 and ESP82 sometimes have different implementations (for example Pin #) and your compiler does not compile without directives.
@lukepage6348
5 жыл бұрын
THIS IS AMAZING! How have I never heard of this 😂
@AndreasSpiess
5 жыл бұрын
There were not many discussions about that recently. It was discussed a few years ago.
@MPElectronique
5 жыл бұрын
Thank you master Andreas :)
@AndreasSpiess
5 жыл бұрын
:-)
@akj7
5 жыл бұрын
I recommand changing Arduino IDE's font, to consolas. You will be surprised how beautiful the editor will look and how the prograsming experience will improve.
@AndreasSpiess
5 жыл бұрын
Done. Especially for you ;-)
@thisusernameismine10
5 жыл бұрын
Prograsm - does that feel as good as it sounds?
@AkosLukacs42
5 жыл бұрын
Or try fira code!
@FantaBH
5 жыл бұрын
one big like for one great video. TY.
@AndreasSpiess
5 жыл бұрын
Thank you!
@aminalwashe3297
5 жыл бұрын
sehr gutes Video! mehr davon
@AndreasSpiess
5 жыл бұрын
Danke!
@ignatiushintergschwendtner7738
5 жыл бұрын
The good old macro ☺
@AndreasSpiess
5 жыл бұрын
Yes!
@Brutaltronics
5 жыл бұрын
so it's normal for the sketches for the ESP8266 to be that massive?
@AndreasSpiess
5 жыл бұрын
The WiFi lib was included
@TomaszDurlej
5 жыл бұрын
Yes, Arduino core for esp32 uses FreeRTOS and espresif ESP-IDF so every even most simple program have pretty huge overhead, and wifi isn't small.
@pfeerick
5 жыл бұрын
Yup, if you compile the blink sketch it'll be massive also - there is all the extra stuff needed for the expressif SDK, etc. But the chip also has a lot more flash memory, so it's not that much of an issue. Blink sketch on ESP8266 core 2.4.2 for generic ESP8266 with default settings is 247940 bytes (49%) of program storage space, 28028 bytes (34%) of dynamic memory... just a minor overhead? :D
@zachreyhelmberger894
5 жыл бұрын
Bravo!!
@AndreasSpiess
5 жыл бұрын
Thank you!
@HiVisl
5 жыл бұрын
“The small man is working.” I’m still laughing 😂
@AndreasSpiess
5 жыл бұрын
:-)
@ChaplainDaveSparks
5 жыл бұрын
What will have you tearing your hair (if any) out is when your code isn't working right, so you put in debug statements and .... the problem goes away. Turn them back off and your code misbehaves again. The problem? You have a timing problem somewhere. Executing debug statements slows it down enough that the problem goes away!
@AndreasSpiess
5 жыл бұрын
That can happen (happened also to me). Maybe you watch the JTAG debugging video. There, the timing issues should go away.
@pfeerick
5 жыл бұрын
Great video Andreas! Whilst I already use pre-processor defines in my code, you've given me some ideas on how to use them a bit differently for different projects. I use the following debug code at present, but will probably take your debugutils, reformat it slightly and add some bits to it and use that, as I like the idea of the levels. I just like the ability to turn debugging off entirely, and if your sketch didn't need Serial, that overhead is completely removed also. Makes a real difference when you are working with other processors such as the Attiny85 ;) #define DEBUG #define DEBUG_OI Serial #ifdef DEBUG #define DebugBegin(...) DEBUG_OI.begin(__VA_ARGS__) #define DebugPrint(...) DEBUG_OI.print(__VA_ARGS__) #define DebugPrintln(...) DEBUG_OI.println(__VA_ARGS__) #define DebugPrintf(...) DEBUG_OI.printf(__VA_ARGS__) #define DebugWrite(...) DEBUG_OI.write(__VA_ARGS__) #else // Define the counterparts that cause the compiler to generate no code #define DebugBegin(...) (void(0)) #define DebugPrint(...) (void(0)) #define DebugPrintln(...) (void(0)) #define DebugPrintf(...) (void(0)) #define DebugWrite(...) (void(0)) #endif
@AndreasSpiess
5 жыл бұрын
Seems to be similar to mine, just without the levels. You could define level0 as no debugging at all in my code. Or you never use DEBUGPRINT0 at all...
@vic6466
5 жыл бұрын
#include
@AndreasSpiess
5 жыл бұрын
??
@tomgeorge3726
5 жыл бұрын
Hi Andreas, top video mate, makes a lot of sense and debugging along with memory management easier to implement. I am wondering if you could turn the debug ON and OFF with an external digital input, even if it meant resetting the controller to read the input?
@AndreasSpiess
5 жыл бұрын
You could do that using variables. Not with these directives. They are only valid before compiling.
@thisusernameismine10
5 жыл бұрын
That's a really top point Tom. I do that atm, eg testing whether a PIR works from distance by lighting a bright led. Press a button, turn off DBG mode. Good reply Andreas. Now enlightened on this subject tho, thank you.
@tronicgr
5 жыл бұрын
how do you add the debugutil library to the arduino IDE? perhaps you could reformat it in Github to allow easy installation as zip library...
@AndreasSpiess
5 жыл бұрын
It is no library. Just copy the directory to your library folder as shown in the video.
@TomaszDurlej
5 жыл бұрын
From this is simple way to make menuconfig stuff. Maby Arduino add it some day in for of drop down menu in ide
@AndreasSpiess
5 жыл бұрын
We will see...
@markludwig5805
2 жыл бұрын
Hey Andreas…you got me thinking about esp8266 preprocessor. Oh great video and I have implemented the debug routine. My esp8266 program has grown and my OTA library and Firebase library are colliding with each other causing crashes. Can you guide me on how to have a dual boot 8266. I’d like to do an OTA on power up, then restart, ESP.restart(), and do Firebase stuff based on ESP.getResetReason != “Power Up” or BOOT_MODE/Reset Cause. I’m able to manually isolate the two boot ups via preprocessor #define statements but can’t figure out how to do it base on checking the condition of ESP.getResetReason , or BOOT_MODE/Reset Cause or other condition you might suggest. Thanks for your help.
@AndreasSpiess
2 жыл бұрын
I hardly use the ESP8266 anymore. Particularly for complex projects :-(
@azertyQ
5 жыл бұрын
Be careful with using large #ifdef blocks in code though. It can make reasoning about the code much more complicated (better to use makefile to distinguish between different execution environments)
@AndreasSpiess
5 жыл бұрын
Unfortunately, we do not use makefiles in the Arduino environment. But usually, these projects are also not too big...
@prathambumb5593
5 жыл бұрын
Best IDE Alternative To Arduino
@AndreasSpiess
5 жыл бұрын
??
@kissingfrogs
5 жыл бұрын
Assuming ESP8266 is defined by the IDE for the #ifdef ESP8266 statement, how can I find out what other defines or declarations are made by the IDE.
@AndreasSpiess
5 жыл бұрын
The only way I know is by googling and watching videos like that :-(
@ErkanOkman
5 жыл бұрын
👍👏
@AndreasSpiess
5 жыл бұрын
:-)
@ahmedgerges3955
5 жыл бұрын
Greetings from iraq
@AndreasSpiess
5 жыл бұрын
:-)
@tulius01
5 жыл бұрын
Klasse Video, vielen Dank! Mir gefällt die Schrift Deines Namens sehr gut, kannst Du mir bitte verraten was das für ein Font ist?
@AndreasSpiess
5 жыл бұрын
Das ist keine „Schrift“, das ist eine Unterschrift ;-)
@tulius01
5 жыл бұрын
@@AndreasSpiess Sieht auf alle Fälle toll aus, ich dahcte abr dass es sichum einen Script-Font handelt, schade ist wirklich toll. Danke für die Antwort und mache weiter mit Deinen tollen Videos, die Sachverhalte sind wirklich gut verständlich erklärt, einfach Spitze!
@DCFusor
5 жыл бұрын
Now, what would be super-good would be an easy way to list all existing defines...it's kind of known by osmosis that ESP8266 (with or without a space??) might be defined - but how to tell what IS defined already? Searching on google makes this seem an unsolved or not universally solved problem....and it'd be nice to be able to use the IDE-created ones which is kinda hard to do without a list of what they might be.
@sbx320
5 жыл бұрын
The gcc compiler has a flag for that. This is a bit outside of the usual Arduino IDE, but it will give you identical results: - Create a new file (called BareMinimum.c) which only contains one line: #include "Arduino.h" - Invoke gcc directly (Note: This assumes an Arduino Mega, needs to be adjusted accordingly for other boards): "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-gcc" -dM -E BareMinimum.c -I "C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" -I "C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega" I'd then suggest sorting it and removing all macros with leading underscores (those are mostly compiler-internal things that will have little to no use or meaning for you). For my Mega I end up with this list: gist.github.com/sbx320/cb4c71419d2bf56e1e583a45ffc888ce -dM lists all defines -E means preprocess only (we do not actually want to build a program, just the defines) -I [path] is an additional include directory, referring to the Arduino Core libs plus the Board specification
@DCFusor
5 жыл бұрын
Excellent. Thanks!
@AndreasSpiess
5 жыл бұрын
@Doug: AFAIK each board has its own defines in Arduino IDE (e.g. pins, LED_BUILT_IN). But I never dug into it so far.
@DCFusor
5 жыл бұрын
Yes, I've run into some of them while surfing some of the source code for the tools. The solution proposed by sbx320 works (and there are other similar ones you find on google) for fairly experienced folk (I'm OK there), but it sure would be nice if there was a _simple_ way to get a list. I've run into name conflicts with things defined in "fruity" libraries for example....#defines are both a blessing and a curse, the latter when they chew up your namespace and you wanted that name for something. Depending on your warning level you can have some interesting times around conflicts..
@svenoberg4738
3 жыл бұрын
One more comment: With #ifdef ... #else ... #endif you create blocks of code that the compiler doesn't check for you. These code-branches that you personaly never use degenerate over time (updated libs, deprecated functions) or never worked at all. Github is full of projects with these problems. So static bool const g_bDebugOutput(true); or static int const g_iDebugLevel(4); may cost you some bytes but makes the maintenance of your code much easier
@AndreasSpiess
3 жыл бұрын
Agreed. Just if you have big parts of a program to switch on or off these pre-compiler directives create much smaller code. I often see it used in this function. But they are not easy to read.
@ntc490
5 жыл бұрын
Two things that go along with this: en.wikipedia.org/wiki/Variadic_macro and stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for Also, be careful how crazy you go with Macros. Too many can really make your code difficult to maintain for humans. There are some general practices that help quite a bit. See the Linux kernel for example.
@AndreasSpiess
5 жыл бұрын
Thanks for your additions!
@BrunoHorta
5 жыл бұрын
COOLLLL :)
@AndreasSpiess
5 жыл бұрын
Thank you!
@fransdebruijn6763
5 жыл бұрын
Your "number sign" ( # ) is called a "Hash"
@AndreasSpiess
5 жыл бұрын
You are right!
@TheNamelessOne12357
5 жыл бұрын
#define true false # Happy debugging :-)
@AndreasSpiess
5 жыл бұрын
Happens also in real life sometimes ;-)
@nogmeerjan
5 жыл бұрын
2:07 is simply wrong. The search and replace is case sensitive and only "whole words" are replaced. 2 examples "led" will not become D1 and "LEDS" will not become "D1S". Preprocessor directives are very powerful and it is easy to break the code. If you are using preprocessors often I would advice a more advanced IDE that visualizes the code better than the Arduino IDE
@ThijsVandenrijt
5 жыл бұрын
He doen't mean this as literally as you do, you should have picked this up when he mentioned the gnome :) On the other hand, i really cannot agree more that a more advanced IDE would be the best "Hack" to improve larger programs. Visual Studio, combined with the Visual Micro plugin (Available from the Visual Studio marketplace) is a really nice IDE and painless to use in an arduino or ESP context.
@AndreasSpiess
5 жыл бұрын
@Jan. Of course, you are right. I could at least have the "ignore case" switched off.
@nogmeerjan
5 жыл бұрын
I didn't want to mention alternatives as I build one myself. But as you started to mention one. Sloeber.io is a open source eclipse based alternative working fine with 500+ boards.
@nogmeerjan
5 жыл бұрын
@Andreas the "ignore case" triggered me.
@AndreasSpiess
5 жыл бұрын
For me as a KZitemr it would be suicide to leave the Arduino IDE...
@ats89117
5 жыл бұрын
Pain in the ass? Is that a technical term? ;-)
@AndreasSpiess
5 жыл бұрын
I think it is more medical ;-)
@danielhawkins3392
5 жыл бұрын
Where is this small man kept? What does he eat? Are there ever small women? So many questions
Пікірлер: 179