GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Friday, 15-Nov-2024 04:13:27 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:

    Why so many people hate C?
    Because the C language assumes you know what you’re doing and lets you. If you don't know what you are doing you can learn or you can hate the language.

    #clanguage #c #programming

    In conversation about 6 months ago from hostux.social permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 01:55:00 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek This is the part: " the C language assumes you know what you’re doing" 😉

      An int overflow is something common to almost any language as far as I know, and the implicit conversions are documented in the C Standard.

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 01:55:01 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa

      other than that (and silent implicit conversions), C has its charm

      Now, C++ - what an abomination!

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 01:55:02 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa

      char c = 0x80;
      if (c == 0x80) {
      puts("C is OK");
      }
      else {
      puts("there's something wrong with C");
      }

      In conversation about 6 months ago permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 01:56:28 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Uli Kusterer (Not a kitteh)

      @uliwitness I'm not saying C is an easy language nor I'm saying everyone has to use it 😉

      In conversation about 6 months ago permalink
    • Embed this notice
      Uli Kusterer (Not a kitteh) (uliwitness@chaos.social)'s status on Saturday, 16-Nov-2024 01:56:30 JST Uli Kusterer (Not a kitteh) Uli Kusterer (Not a kitteh)
      in reply to

      @lfa Or maybe life is too short to use a language that has so many wrong defaults, undefined/implementation-defined behaviors etc., when, instead of trying to remember all the things you shouldn’t do, you could just use a language that does the right thing by default, freeing your brain up to actually design and plan the parts that make your program special.

      Maybe I'll finally know what I'm doing and will learn after another 29 years of writing C.

      In conversation about 6 months ago permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 02:18:39 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek Some conversions are implementation dependent not all of them.

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 02:18:40 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa no it doesn't. It is implementation-dependent.

      In conversation about 6 months ago permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 02:57:58 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek Sorry I thought you where talking about the conversions.

      Your sample of the int overflow is going to get caught if you set the warning flags of the compiler, and because your affirmation sounded odd to me, I tested your sample on GNU/Linux with GCC 12 and on OpenBSD with clang 16 and I got exactly the same result.

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 02:57:59 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa what does int overflow have to do with that?

      In conversation about 6 months ago permalink
    • Embed this notice
      pinskia (pinskia@hachyderm.io)'s status on Saturday, 16-Nov-2024 03:05:22 JST pinskia pinskia
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek @lfa oh yes the implicit conversion to int. It is even worse if you do: '\0x80' as in C++ it would the char type while in C it is still int.
      Oh and is char signed or unsigned depends on the target.

      In conversation about 6 months ago permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 03:17:51 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek because char, unsigned char and signed char are integer types.

      A char can contain a value from -128 up to 127. 0x80 is 128 so when you set 0x80 to a char variable it's going to overflow. That's why your if fails because you are comparing if your char is 128 and it's not.

      If you use an unsigned char which can hold values from 0 to 255 then your if is going to work as expected.

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 03:17:52 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa but I still don't get what this has to do with int overflow

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 03:17:53 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa (but I trust that they both conform to the C language specification)

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 03:17:54 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa I tested here https://www.onlinegdb.com/8ejcl5Le9A (gcc 11.4.0) and on clang 16.0.4, and only clang behaved sanely.

      In conversation about 6 months ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: www.onlinegdb.com
        GDB online Debugger | Code, Compile, Run, Debug online C, C++
        Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 16-Nov-2024 03:53:45 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Panicz Maciej Godek

      @PaniczGodek you're right it's a conversion I mixed concepts sorry.

      In conversation about 6 months ago permalink
    • Embed this notice
      Panicz Maciej Godek (paniczgodek@functional.cafe)'s status on Saturday, 16-Nov-2024 03:53:46 JST Panicz Maciej Godek Panicz Maciej Godek
      in reply to

      @lfa Overflow is something that happens during arithmetic operations. When I set 0x80 to a char variable (assuming it's at least 8-bit wide), that variable contains exactly this value: 0x80 (or bit pattern 0b10000000). There is no overflow.

      The problem arises with the operator ==, which performs a widening conversion of the variable to the "int" type, because it treats that variable as a signed value (which is implementation-dependent, which is a problem on its own), and instead of treating it as 0x80, it treats it as 0xFF80 (on 16-bit platforms) or 0xFFFFFF80 (on 32-bit platforms), because this is how widening conversion with 2's complement number representation works.

      In conversation about 6 months ago permalink
    • Embed this notice
      Jean-Baptiste "JBQ" Quéru (jbqueru@fosstodon.org)'s status on Saturday, 18-Jan-2025 21:46:06 JST Jean-Baptiste "JBQ" Quéru Jean-Baptiste "JBQ" Quéru
      in reply to

      @lfa C made so much sense to me when I learned it after years of programming almost exclusively in assembly.

      In conversation about 4 months ago permalink
    • Embed this notice
      lfa :emacs: :tux: :freebsd: (lfa@hostux.social)'s status on Saturday, 18-Jan-2025 21:46:06 JST lfa :emacs: :tux: :freebsd: lfa :emacs: :tux: :freebsd:
      in reply to
      • Jean-Baptiste "JBQ" Quéru

      @jbqueru Sure thing. Knowing asm makes it a piece of cake to learn C, and knowing C also makes easier to start to get the sense of asm.

      In conversation about 4 months ago permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.