A const int is not a constant.

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
A const int is not a constant // seriously. It's one of the oddest things about C, but it's true. In this video, I'll show you a few examples.
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Пікірлер: 348

  • @greg4367
    @greg4367 Жыл бұрын

    Up for a challenge: Enplane to the newbie C programmer the differences in use of volatile , const, and static as applied with scope global, file global and function. Good luck. Fifty years of coding in C (yes, it is still my goto language) I still sometimes get tripped up. But all languages have these problems, as in: Throw the horse over the fence a bale of hay.

  • @johnheaney3349
    @johnheaney3349 Жыл бұрын

    Macros are not C "constants"; they are literals. They compiler does not even see macro definitions because they are preprocessed before compilation. They are only constants in the sense that literals are a type of constant, but again, the compiler does not see or process macros. If you look at the preprocessor output, the macros are completely gone.

  • @eddiebreeg3885
    @eddiebreeg3885 Жыл бұрын

    Cppreference: "Constants, by their simplest definition, are values that do not change."

  • @ABaumstumpf
    @ABaumstumpf Жыл бұрын

    This is a Video that tries to talk about the intrinsics and fundamental behaviour of 'C' - but fails horribly at that.

  • @xarcaz
    @xarcaz Жыл бұрын

    It IS a constant. Just not a compile-time constant (such as pre-processor defines, enum values, and C++ constexpr values).

  • @knightflyer909
    @knightflyer909 Жыл бұрын

    It is worth remembering that when coding for many microcontrollers "const" will place the value in the program store (often times Flash). From a practical point view this means the value will be read-only. This just an addition to already excellent video.

  • @georgecop9538
    @georgecop9538 Жыл бұрын

    2:17

  • @eriks2962
    @eriks2962 Жыл бұрын

    Hey Jacob,

  • @Siger522
    @Siger522 Жыл бұрын

    Actually literals in C (i.e. what

  • @maxaafbackname5562
    @maxaafbackname5562 Жыл бұрын

    10 is a integer literal.

  • @adecy9669
    @adecy9669 Жыл бұрын

    Great video, in embedded systems we usually use "volatile const uint32_t *reg = 0x04000000u;" to describe a read-only register (like a hypothetical UART RX DATA register). It's not possible to write to the register, but we can read from it, and each time we read it we can get a different value ! And the volatile make it even funnier.

  • @nicholaswood3250
    @nicholaswood3250 Жыл бұрын

    In C (and any language really), the guardrails are there for you and not the machine. Everything depends on your willingness to engage with the languages’ constraints in good faith (unless you’re just breaking things for fun)

  • @llllNEOllllchannel
    @llllNEOllllchannel Жыл бұрын

    What do you mean under "constant is not really constant but read only entity since we intialized it"? How else would you describe or define constant if it is not just read-only entity?

  • @lipcioful
    @lipcioful Жыл бұрын

    Finally, a great, interesting and professional C content on YT ☺

  • @SassyToll
    @SassyToll

    Thank you, I love your course on C/C++ I have learn so much, I really appreciate what you are doing

  • @10vid5
    @10vid5 Жыл бұрын

    I've always liked the

  • @praktexemplar8082
    @praktexemplar8082 Жыл бұрын

    Hey Jacob, great video.

  • @-wx-78-
    @-wx-78- Жыл бұрын

    This reminds me of Fortran's numeric literals that are actually variables - they can be modified (mostly by accident) when used as subroutine parameters because of “pass by reference” calling convention.

  • @peircedan
    @peircedan

    Since you have posted a clarification video I'm surprised you have not changed the title to this one and also have not pinned a link to the clarification (which has far fewer views than this one).

  • @Carolus_64
    @Carolus_64 Жыл бұрын

    Before making a video on "exotic" constexpr please explain the const used with pointer and how to declare a