Macros in C++

Поділитися
Вставка
  • Опубліковано 24 лис 2024

КОМЕНТАРІ • 270

  • @karmaindustrie
    @karmaindustrie 5 років тому +549

    #define print(x) std::cout

    • @IamusTheFox
      @IamusTheFox 5 років тому +65

      Or with type safty, and proper compile time checking:
      template
      constexpr void print(Tostream ostrem = std::cout, Tlimit end='
      ' ,TStr ... to_print)
      {
      (std:: cout

    • @kcvinu
      @kcvinu 5 років тому +51

      #define begin {
      #define end } ;
      voilà ! pascal. And use just "end", voilà ! Ruby. :) cpp is really fun.

    • @ShadowaOsu
      @ShadowaOsu 5 років тому +12

      @@IamusTheFox you defined a template Tostream and never used it lmao

    • @IamusTheFox
      @IamusTheFox 5 років тому +4

      @@ShadowaOsu lmao, you're right, my bad.

    • @ShadowaOsu
      @ShadowaOsu 5 років тому +7

      ​@@IamusTheFox also it gives compile error for various of inputs when used in main, so I tried to give it a try as well
      struct End {
      const char* end;
      constexpr End() : end("
      ") { }
      constexpr End(const char* end) : end(end) { }
      };
      template
      constexpr auto pyprint (const First& first, const Rest& ...rest) -> void {
      if constexpr (sizeof... (rest) > 0) {
      std::cout

  • @DiamondShocked
    @DiamondShocked 4 роки тому +55

    I think it would also be helpful to show common pitfalls of parameterized macros, such as the following 2 examples:
    ===================
    #define MAX(x, y) x > y ? x : y
    int main() { return MAX(7,5) * 10; }
    Here main() will return 7 instead of 70:
    7 > 5 ? 7 : 5 * 10 ==> 7
    To fix this, do:
    #define MAX(x, y) (x > y ? x : y)
    ===================
    Another issue can be seen in this example:
    #define MULT(x, y) (x * y)
    int main() { return MULT(2+5, 10); }
    Here main() will return 52 instead of 70:
    2+5*10 ==> 52
    To fix this, do:
    #define MULT(x,y) ((x) * (y))
    Of course, y can be a pointer so it is possible that *(y) is seen as a dereference. In addition, either x or y can be almost any text which can result in weird generated code.
    ===================
    The takeaway is that parameterized macros are NOT functions: they simply replace symbols with parameterized text.
    This can also result in the problem of massive code duplication, since a parameterized macro does not define a function in the program text segment, but is rather copied to every invocation.

  • @Banom7a
    @Banom7a 7 років тому +727

    #define true false

  • @johnsmith-ci5ib
    @johnsmith-ci5ib 4 роки тому +58

    These have got to be the most concise and clear programming videos I've seen thus far.

  • @nimrodhawk4011
    @nimrodhawk4011 4 роки тому +146

    The thought of seeing an “OPEN_CURLY” macro in real life cracked me up...at that point you know you’re dealing with a high-effort troll lmao

    • @sebastiangudino9377
      @sebastiangudino9377 2 роки тому +12

      I once saw a
      #define begin {
      #define end }
      And it was honestly a pretty wild experience. That simple change made C++ feel a hell of a lot like Ruby or Basic. Like:
      void main() begin
      if (1 > 0) begin
      printf("whatever
      ");
      end
      end
      Doesn't that look wild?

    • @failgun
      @failgun 2 роки тому +7

      @@sebastiangudino9377 reminds me of Lua too

    • @zltn_brkl
      @zltn_brkl 2 роки тому +4

      #define semicolan ;

    • @jstro-hobbytech
      @jstro-hobbytech 2 роки тому +21

      My wife was like "what are you laughing so hard at?". I told her she wouldn't understand. She made me explain. She didn't understand.

    • @GenericPhantom1
      @GenericPhantom1 Рік тому +4

      Saw one image where he just defined some stuff and the code was like "frfr no cap" and he just replaces so many things with just random words and it looks like a sentence.

  • @firerazzer
    @firerazzer 9 місяців тому +4

    Really usefull compiler option : -E
    It wills just process the precompiler routine and output your source code with all macro expanded.
    For example : g++ -E main.cpp -o main.e

  • @DanielLiljeberg
    @DanielLiljeberg 6 років тому +105

    As some might have noticed the "blank" macro would actually not remove the entire LOG line in the code. It would leave the ";". This might cause people to want to include the ";" in the macro instead of writing it after the macro in the source code since that would not leave a line with just a ";". But a line with only ";" is totally acceptable and is just an empty statement which a decent compiler would most likley simply discard although there might exist some compilers that would actually insert NOOP instructions.
    Point is, ";" by itself on a line is perfectly legal code.

    • @nathannlatimore7863
      @nathannlatimore7863 4 роки тому

      Thanks for the clarification! Really appreciate it!

    • @logangraham2956
      @logangraham2956 3 роки тому +1

      but you might want to be aware of this if it isn't by itself.

    • @robertmoats1890
      @robertmoats1890 3 роки тому +8

      Its sometimes better to define the empty output as "{}" or "((void)0)" - These will make it a valid line of code without it doing anything. This is important if your macro can be called from within a single condition line, like if(x) MACRO();

    • @Laevatei1nn
      @Laevatei1nn 3 роки тому

      called null statement

  • @hallerinstruments318
    @hallerinstruments318 4 роки тому +30

    You're an excellent educator. Great job! This was super helpful.

  • @psposki
    @psposki 5 років тому +6

    It's so comfy to watch it, I wish my lecturer was talking and makeing examples like you.

  • @syeduthman
    @syeduthman 6 років тому +35

    I use macros for Embedded microcontroller to configure my hardware easily.

  • @neiltsakatsa
    @neiltsakatsa 7 років тому +26

    Streams, Input and Output. As well as Files

  • @zaviermiller8980
    @zaviermiller8980 2 роки тому

    Bruh I love that I can expect a good ass cherno video on any cop topic I might want to learn. Really appreciate the work man 🙌🙌🙌

  • @darealshinji
    @darealshinji 3 роки тому +5

    Other real life examples for macros would be to target different platforms. You write a conditional to decide between using Windows API or POSIX API. Or you want to do different stuff for an ARM build compared to x86. In open source projects macros are often used for optional features which might be enabled during configuration, like building ffmpeg with lots of optional third party libraries enabled. You can use macros to enable compiler specific stuff, like telling msvc right in the code to link against a library, but you want that part to be "excluded" for other compilers that don't understand or need this. Macros may also play a role when you build static libraries and DLLs for Windows, as the symbols in a header file need to be declared as either importing or exporting code or none of that.

  • @kaydenstevens5193
    @kaydenstevens5193 5 років тому +6

    The advice at 3:20 is golden bro!

  • @scullyy
    @scullyy 8 місяців тому +1

    It no longer becomes simple copy paste when using any punctuation characters in the macro name. This code here for example, is not allowed:
    #define print(x) std::cout

  • @redcollard3586
    @redcollard3586 2 роки тому

    Thanks for these videos man, I'm reading "Code Complete" and I thought I was getting to know C++ and C pretty well but everything he says about macros has gone over my head. This clears everything up, as so many of your videos do. The Static and Cost ones are my other favorites so far can't wait to see the rest this series is literally better than a college education.

  • @koenderbb5191
    @koenderbb5191 4 роки тому +8

    Hi Cherno,
    I know you will touch / have touched upon macros in more depth in your game engine / opengl series, but could you still make a separate video that's purely about macros (a part 2 of this one)? Because I don't follow your game engine / opengl series but I would still like to learn more about it from you.
    Thanks ~

  • @Fronzel.Neekburm
    @Fronzel.Neekburm 3 роки тому +3

    Great series, these are presented really well. I don't understand why "#ifdef symbol" or "#ifndef symbol" is bad though. Header files have used this method to see if it has already been included for ages, windows header use it a lot and use it to set function names for Unicode or ascii. Would have been a good time to explain the underscore in symbol names. Still great simple video series worth watching.

  • @Mario112352
    @Mario112352 7 років тому +7

    Really like your C++ series.
    Wondering if you could do some videos on MVS Windows GUI.
    Not much out there on the Windows GUI, I know there are at least one error with MVS 17 in loading a Windows GUI setup. This is really tough for beginners.
    Thanks,

  • @PeterPetrakis
    @PeterPetrakis 7 років тому +2

    Your example of logging bytes would be better served by creating a custom allocator that handled the metrics. Then you would override new to use your allocate/create functions. The bonus here is that you could add that allocator to a container and reap the same benefits.

    • @TheCherno
      @TheCherno  7 років тому +1

      Yes, but you still might want to track the file and line the allocation came from, which would require a macro.

  • @robertmoats1890
    @robertmoats1890 3 роки тому +2

    In some cases, you may want to define your empty macro (the release version) as "{}" or "((void)0)", such as..
    #define MACRO(x) ((void)0)
    This will result in the macro generating a valid line of code that doesn't actually do anything. This would be important, if for example, you wanted to use it in places such as..
    if( xyz )
    MACRO(x);
    I usually define a special "#define EMPTY_STATEMENT ((void)0)" somewhere near the top of my code to be used in these cases. It makes the macros themselves a little more readable ( #define MACRO(x) EMPTY_STATEMENT )

  • @likestomeasurestuff3554
    @likestomeasurestuff3554 7 років тому +2

    Thank for this series, helps a lot

  • @logangraham2956
    @logangraham2956 3 роки тому +4

    actually the
    LOG(...);
    in release mode would become
    ;
    because the semicolon was not defined in the macro.

  • @LoneDWispOfficial
    @LoneDWispOfficial 2 роки тому +3

    video idea for anyone just for fun: Making c++ looks like another programming language, using only MACROS!

  • @maryambeygmohammadi2232
    @maryambeygmohammadi2232 2 роки тому +1

    good explained and helpful, thanks Cherno!

  • @billbez7465
    @billbez7465 4 роки тому

    Excellent C++ series. I am now a patreon.

  • @djupstaten2328
    @djupstaten2328 Рік тому +1

    Thank you for these incredible videos. I noticed in VS Code, some C++ I had installed offered a -- *lightbulb* | "inline macro?" | -- clickable tooltip that will let you graphically resolve whatever macro you are currently hovering over. Surely there are tools in actual Visual Studio to do that globally? Or stepwise for safety.

  • @AssemblyWizard
    @AssemblyWizard 6 років тому +9

    Another problem with the code is that LOG in release mode doesn't force a semicolon.

  • @RoshanPradhan2
    @RoshanPradhan2 4 роки тому +29

    Let's make Python with #define 😂

  • @kiritsuna
    @kiritsuna 4 роки тому

    This video really helped me understand a lesson of learncpp, thanks a lot

  • @OzieCargile
    @OzieCargile 3 роки тому

    You are an excellent teacher.

  • @leixun
    @leixun 4 роки тому +9

    *My takeaways:*
    1. Create a Macro 3:52
    2. Better use of Macros 7:47
    3. Using Macro to differentiate debug code and release code 9:50
    4. Macros are most useful for debugging purposes 15:42

    • @drtidrow
      @drtidrow 3 роки тому

      They're also useful for encapsulating OS-specific code.

  • @RootsterAnon
    @RootsterAnon 4 роки тому +3

    if Anyone is watching this in 2020. If your Debug Code is not recognized after checking for PR_DEBUG you just need _DEBUG now. Hope this helps.

  • @strawberriecherrie
    @strawberriecherrie 4 роки тому +1

    I am learning SOOOO much more than what i did i uni!

  • @gwennigboudeau7512
    @gwennigboudeau7512 4 роки тому

    Very good video and clear explanation

  • @ogox
    @ogox 7 років тому +4

    Hey, great videos! Can you please make a video about the volatile keyword? :)

  • @Rakesh-yu1pb
    @Rakesh-yu1pb 5 років тому +2

    what an intelligent human being.

  • @bluescanfly1981
    @bluescanfly1981 2 роки тому

    Macros are useful for writing parametrized test cases or "procedurally generated" code in general.
    Clojure / Lisp take it to the next level with homoiconicity (code and data are the same thing)

  • @Cyraxx13
    @Cyraxx13 7 років тому +87

    Please don't pull another "Cherno" on us. Like you hype us with your quality content and then suddenly dissapear for half a year... :(

  • @marcinlesniewski4571
    @marcinlesniewski4571 4 роки тому

    Elegancko

  • @ZER02641988
    @ZER02641988 6 років тому +4

    When we can expect the video in which you are going to show macros in more details and built in macro types , mentioned in this video?

  • @VasaMusic438
    @VasaMusic438 6 років тому

    your indications are very wise, thanks a lot !!

  • @jadespy399
    @jadespy399 3 роки тому

    Another reason why it might not be the best -- although IMO it's silly -- is that someone might tack a

  • @kcvinu
    @kcvinu 5 років тому

    You are really great. I started learning cpp in 2013 but quit learning only because of curly brackets and over use of symbols like "

    • @piechulla1966
      @piechulla1966 4 роки тому

      This joke has probably been cracked over 100000 times since Kernighan & Ritchie presented C in 1971.

  • @hsmhsm327
    @hsmhsm327 2 роки тому

    Java: *public static void main* is untouchable if you want your code to compile.
    c++: hold my *MAIN_MARCO CHAR_EXCLAMATION*

  • @onepersonintheuniverse
    @onepersonintheuniverse 3 роки тому

    The Cherno: C++
    Subtitles/CC: *zip ocelots*

  • @chainonsmanquants1630
    @chainonsmanquants1630 4 роки тому

    Thanks

  • @sanskar_choudhary
    @sanskar_choudhary 3 роки тому

    Nice explaination 👍🏻

  • @coolkoala282
    @coolkoala282 4 роки тому +2

    Both Programming and English can be learned by watching your videos

  • @sylvesteruchia5263
    @sylvesteruchia5263 Місяць тому

    "This isn't some kind of obfuscation competition "
    People watching for an obfuscation competition :....

  • @ZzBiazZ
    @ZzBiazZ 7 років тому +1

    thank you

  • @MegaNightdude
    @MegaNightdude 4 роки тому

    Awesome!

  • @behrampatel3563
    @behrampatel3563 3 роки тому

    You would have made an excellent Unreal Engine C++ trainer. Please do consider making a course on UE C++

  • @Daninshit
    @Daninshit 3 роки тому

    Define macros are easy, the difficult is to read, most of the time you don't know where they are and what they do. Some code depend of some macros to be defined and the docs sometimes don't put so much effort in explain it, and that's really confusing.

  • @drwisdom1
    @drwisdom1 4 роки тому +17

    Typically Mr. Cherno's videos are informative, but I found this video disappointing in many ways. I have been programming C and C++ since 1982 and believe in portability. Macros get you there.
    1) It is very hard to overuse macros. I never use int, long, size_t, or double. Instead I use LSINT, LSLONG, ... so I can change their size with just a recompile. If you want to make data compatible between 32 and 64 bit programs you need that capability.
    2) I have macros like LSCCPC which expands to "const char* const". That saves a bundle of typing and makes the code easier to read.
    3) Never use special numbers in your code, define them as macros. So if you needed to use 3.14159 in your code you would "#define PI 3.14159" and then use PI in your code so it becomes readable and can be globally modified if needed (which would never occur with PI).
    4) Never use an external call more than once. If you wanted to call "std:cin.get( )" more than once, make it into a member function with a readable name like GetInput(). If you use a macro it is duplicated in every location it appears. That is especially wasteful for strings, so don't use #define with multi-use strings (use a static instead).
    5) Don't put macros into your compiler GUI! Keep them in the code where they belong. You are making your program dependent on the compiler on a specific computer! Put it in a header and include the header. I put both possibilities and then uncomment the one I want to use.
    #define FOO_DEBUG 0
    // #define FOO_DEBUG 1
    6) One of the most important uses of macros is to unify compilers and platforms so all computing environments appear the same. Inside my call to get the available disk space I have code similar this:
    #if MSDOSSYSTEM
    size = msdos_diskspace( );
    #elif ANYWINDOWSYSTEM
    size = windows_diskspace( );
    #elif LSANDROID
    size = android_diskspace( );
    #elif UNIXSYSTEM
    size = unix_diskspace( );
    #else
    #error need diskspace for this platform
    #endif
    7) The reason you almost always use #if instead #ifdef is if you typo the macro with #if it fails during compilation. If you use #ifdef it compiles with you thinking the code was included when it wasn't because of the typo, leading to unnecessary debugging hassles and wasted time that would have been avoided with #if.
    8) The standard going back to C is to capitalize macros so when you read the code it tells your mind they get substituted.

    • @darealshinji
      @darealshinji 3 роки тому +1

      For 1) and 2) you normally would use typedefs. For 3) a macro is fine but using a const variable may do the same in some cases. For 6) I would rather put the conditionals inside my own diskspace function or define diskspace as a macro so that I don't have to potentially type these conditionals multiple times in my code.

    • @drwisdom1
      @drwisdom1 3 роки тому

      @@darealshinji Actually I do use typedefs for 1) but since I capitalize them they look like macros and I forgot. But I do use macros with 2) when using const and pointers.

  • @aaamos16
    @aaamos16 Рік тому +1

    Why can't you put template functions in.cpp files

  • @muhamadabdulsamad2815
    @muhamadabdulsamad2815 6 років тому +7

    Hey Cherno, thanks for your wonderful lectures they're really awesome and they helped me a lot! But the only tiny problem is in your lessons when you going through the lessons you speak and explain so fast lol so I'm asking if you just could be a bit slower for sharing knowledge about c++ I'll be grateful
    Thanks for everything ~ 😁

    • @b0606089
      @b0606089 4 роки тому +4

      Reduce the playback speed to 0.75x.

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому

    Awesome.

  • @CheckmateStallioN
    @CheckmateStallioN 4 роки тому

    Wouldn't it be usually better to use inline functions instead? They are safer and the performance difference is negligible. I know function calls use more cpu cycles but from my understanding inline functions are very optimized. I remember this from Effective C++ book

  • @footballCartoon91
    @footballCartoon91 4 роки тому

    @3:02
    Damn,
    That was useful
    Because I don't like to type
    "std::cout

  • @Symphonixz
    @Symphonixz 2 роки тому

    this is cool and all, but wouldn't this require wrapping a good portion of code with "LOG(x)" or are you just using Macros for short code to become shorter? Excuse me for being dumb here, but could you give me another example where you could use Macros to do "stuff" as it is currently shown to put shorter code instead of typing the larger amount. I do find it interesting where you showed in "Release Mode" some code can be used or not used.

  • @relytheone853
    @relytheone853 Рік тому

    Where should I move on after finishing these series?

  • @ccpmustfall6445
    @ccpmustfall6445 3 роки тому

    For people having issues for ifdef DEBUG not showing correctly.
    Use #Ifdef _DEBUG
    I think the visual studio 2019 changed something for the debug :)

  • @xvitxr
    @xvitxr Рік тому

    i'll just leave this one here
    #define integer int
    #define main_execution main(int, char**)
    #define executes {
    #define wait std::cin.get()
    #define then ;
    #define ends_execution }
    integer main_execution executes
    wait then
    ends_execution

  • @YXalr
    @YXalr 7 років тому +3

    Wouldn't
    #define LOG(x)
    leave an extra semicolon in the code as it is not part of the definition?

    • @rcookie5128
      @rcookie5128 7 років тому +5

      yes it would in his example, but just a semicolon without any statements doesn't do anything

  • @higuy55100
    @higuy55100 7 років тому +1

    2:24 Double negative : "nothing you can't not replace" = "nothing you can replace"

  • @RealityCheck6969
    @RealityCheck6969 Рік тому

    They should have used an assignment operator. People would understand instantly.

  • @ViktorBudylin
    @ViktorBudylin 2 роки тому

    Slack in Unreal Engine uses macroses extensively and code becomes so cryptic...

  • @zdenkobrazda4041
    @zdenkobrazda4041 4 роки тому

    ILOVETHIS

  • @kenan2386
    @kenan2386 3 роки тому +2

    /* use this at your own risk */
    #define true false
    #define int
    #define if while
    #define else
    we do a large amount of trolling

  • @nickmichael7206
    @nickmichael7206 6 років тому

    Would using the # define WAIT std::cin.get() still be bad for debugging purposes? If I am not using vim or some text editor that doesn't have break points, that looks like a pretty quick way to use my own sort of break point, especially if I am going to delete it after I am done writing the code anyway.

  • @rcookie5128
    @rcookie5128 7 років тому

    yay!

  • @shipweck6253
    @shipweck6253 Рік тому

    3:33 OOP programmers: nah im gonna make everything OOP

  •  7 років тому

    very good. can you train qt. so we can make mobile application without lost of change of our code. Qt has opengl, opengl-es(angle) and vulkan implementations

  • @thang8617
    @thang8617 2 місяці тому

    How to use in class like Juce framework? In source code of Juce that has "class JUCE_API ClassName {}"

  • @TheDa6781
    @TheDa6781 3 роки тому

    OMG thank you.This is exactly what i was looking for. OPEN_CURLY it is. No.. WAIT

  • @huyvole9724
    @huyvole9724 6 років тому +1

    Now I realize Properties >> C/C++ >> Preprocess Def is macro.
    I remember when I used static/dynamic library, I into Properties >> Linker blah blah ... hahahahahah Now I confident to use macro #pragma comment(lib, "nameLib.lib")

  • @henrikschou3789
    @henrikschou3789 7 років тому

    Many a video about APIs I here about them all the time. I wood like to know: Wot they are and how they works?

  • @YamamotoGenryusaiShigekuni
    @YamamotoGenryusaiShigekuni 2 роки тому +1

    I have a question. Can we redefine a preprocessor directive? For instance (#define ADD_LIB #include)

    • @MaxCE
      @MaxCE Рік тому

      it doesn't work for normall defines

    • @MaxCE
      @MaxCE Рік тому

      as for macros it doesn't work because # has a special meaning in macros

  • @jannesopanen8032
    @jannesopanen8032 3 роки тому

    Good tutorial but if you use #define LOG(x), without anything, it compiles and works fine but the error code i get is weird? not 0 or 1.

  • @ЭнрикеЧурин
    @ЭнрикеЧурин 3 роки тому

    So you can create lua with macros, end is }, and so on

  • @abhijeetjain04
    @abhijeetjain04 6 років тому

    #DontstopOPENGLseries , lot of things are still to be covered in there !!!

  • @GenericPhantom1
    @GenericPhantom1 Рік тому

    Macros are just #define.
    Example:
    #define end }
    Now you can put end and it will type out }

  • @relytheone853
    @relytheone853 Рік тому

    Can I set debug mode in Linux using vscode?

  • @youssofprogrammer2389
    @youssofprogrammer2389 2 роки тому

    3:28 ? Dont you Memories What Should You tell us Or Not?

  • @bunty9560
    @bunty9560 4 роки тому

    @Cherno What Should I start first, 'Game Engine' playlist or 'OpenGL' ?

    • @koenderbb5191
      @koenderbb5191 4 роки тому +1

      I haven't seen either, but I guess it would make more sense to start with OpenGL

  • @haos4574
    @haos4574 6 років тому

    Function pointers needed

  • @dognip
    @dognip 4 роки тому +1

    3:50 you're welcome

  • @ali.sheharyar.sheikh
    @ali.sheharyar.sheikh 7 років тому +2

    Typedefs?

  • @rogerbreton6412
    @rogerbreton6412 4 роки тому

    Do you do any consulting?

  • @akshaynaik4888
    @akshaynaik4888 7 років тому +9

    Please make more videos on templates

  • @MaxCoplan
    @MaxCoplan 5 років тому +1

    Why does he build for x86 and win32?

    • @piechulla1966
      @piechulla1966 4 роки тому

      Google WOW64 or watch all TheCherno clips. Imagine a customer who still wants to run your application on 32 bit windows. Imagine the effort to maintain two versions of your application. You understand?

  • @kitanowitsch
    @kitanowitsch 4 роки тому

    Nordic nRF SDK for their microcontrollers is completely written in macros (C not C++). It's a nightmare.

    • @darealshinji
      @darealshinji 3 роки тому

      I've once seen a tiny single header file PNG decoder which was written almost entirely using macros. It was... interesting.

  • @lathikawathsara2649
    @lathikawathsara2649 15 днів тому

    good

  • @DainYanuka
    @DainYanuka 5 років тому

    Does usage of macros effect performance or increase time in compilation since it needs to replace texts, like specially if the program has large number of macros?

    • @angelcaru
      @angelcaru 3 роки тому

      If you have a large number of macros, you should probably reconsider your code.

    • @BukanChurchill
      @BukanChurchill 2 роки тому +1

      @@angelcaru or your programming career

  • @efec741
    @efec741 13 днів тому

    la gente ne büyük adam keşke

  • @eotcoldhymns2930
    @eotcoldhymns2930 4 роки тому

    What IDE are you using or do you recommend for C/C++ development on linux?

    • @xrafter
      @xrafter 4 роки тому

      @Artem Katerynych
      Clion is available in linux

    • @chiragsingla.
      @chiragsingla. 3 роки тому

      I don't use ide I use visual studio code with c++ extension and cmake extensions

  • @jannesopanen8032
    @jannesopanen8032 3 роки тому

    Never mind, apparently I broke my ten beer limit, so this one is on me.

  • @milan_shah
    @milan_shah 4 роки тому

    This video was quite helpful.
    Could you please make a similar video but using VSCode? Thank you in advance!

  • @MichaelYoussry
    @MichaelYoussry 7 років тому +3

    How is that different from inlined functions?

    • @TheCherno
      @TheCherno  7 років тому +8

      Macros have nothing to do with functions, they're just text that is replaced. You could use them like a function, however you can do so much more with them. We'll explore this in later episodes.

    • @TheCherno
      @TheCherno  7 років тому +1

      Functions will get inlined if you use the appropriate keyword (eg. __force_inline for MSVC).

    • @somedude4122
      @somedude4122 7 років тому

      @TheChernoProject The code it will create tends to be the same though.

    • @courier7049
      @courier7049 6 років тому +2

      The fact that an "inline" function is inlined is decided by compiler, macros do not care about type safety or code syntax as they are parsed at preprocessing phase and are simple "find/replace" expressions. The most fun is to debug a macro because if for an inline function debugger will jump into function in case of a macro there is no code to jump to as the name of the macro was already replaced with specific text.

    • @somedude4122
      @somedude4122 6 років тому

      Well, yes, but macros are really useful where such text replacement is needed.