Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I love C where types are basically a suggestion rather than a rule

I love C where types are basically a suggestion rather than a rule

Scheduled Pinned Locked Moved The Lounge
data-structures
77 Posts 35 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

    Real programmers use butterflies

    M K T Kornfeld Eliyahu PeterK Greg UtasG 21 Replies Last reply
    0
    • H honey the codewitch

      The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

      Real programmers use butterflies

      M Offline
      M Offline
      Mike Hankey
      wrote on last edited by
      #2

      You've never really programmed until chasing a pointer problem.

      I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

      H M 2 Replies Last reply
      0
      • M Mike Hankey

        You've never really programmed until chasing a pointer problem.

        I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        It's good for you - puts hair on your chest.** ** I don't know what to tell if you aren't looking for that. :~

        Real programmers use butterflies

        OriginalGriffO M B 3 Replies Last reply
        0
        • H honey the codewitch

          The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

          Real programmers use butterflies

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          some days ago some young collegue casted his enum to mine and I wondered why the program crashed. :~

          Press F1 for help or google it. Greetings from Germany

          H E 2 Replies Last reply
          0
          • K KarstenK

            some days ago some young collegue casted his enum to mine and I wondered why the program crashed. :~

            Press F1 for help or google it. Greetings from Germany

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            That's half the fun! :laugh:

            Real programmers use butterflies

            1 Reply Last reply
            0
            • H honey the codewitch

              It's good for you - puts hair on your chest.** ** I don't know what to tell if you aren't looking for that. :~

              Real programmers use butterflies

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              honey the codewitch wrote:

              I don't know what to tell if you aren't looking for that

              "Shave"?

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • H honey the codewitch

                The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                Real programmers use butterflies

                T Offline
                T Offline
                The Other John Ingram
                wrote on last edited by
                #7

                I had a legacy program that had void****** as part of a sort routine. It worked, i didn't now how. The guy that wrote it was long gone and i spent a afternoon trying to figure out how it worked. In the end i left it alone.

                H N E 3 Replies Last reply
                0
                • H honey the codewitch

                  The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                  Real programmers use butterflies

                  Kornfeld Eliyahu PeterK Offline
                  Kornfeld Eliyahu PeterK Offline
                  Kornfeld Eliyahu Peter
                  wrote on last edited by
                  #8

                  Everything is a pointer for your interpretation...

                  "The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012

                  "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                  H J 2 Replies Last reply
                  0
                  • T The Other John Ingram

                    I had a legacy program that had void****** as part of a sort routine. It worked, i didn't now how. The guy that wrote it was long gone and i spent a afternoon trying to figure out how it worked. In the end i left it alone.

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #9

                    :laugh: :laugh: :laugh:

                    Real programmers use butterflies

                    1 Reply Last reply
                    0
                    • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                      Everything is a pointer for your interpretation...

                      "The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #10

                      yes to this :-D

                      Real programmers use butterflies

                      1 Reply Last reply
                      0
                      • H honey the codewitch

                        It's good for you - puts hair on your chest.** ** I don't know what to tell if you aren't looking for that. :~

                        Real programmers use butterflies

                        M Offline
                        M Offline
                        Mike Hankey
                        wrote on last edited by
                        #11

                        Don't know about hair but I've learned enough foul language to make a sailor blush.

                        I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

                        1 Reply Last reply
                        0
                        • H honey the codewitch

                          The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                          Real programmers use butterflies

                          Greg UtasG Offline
                          Greg UtasG Offline
                          Greg Utas
                          wrote on last edited by
                          #12

                          Such a right-thinking person. :thumbsup: Are you implying that there are languages that don't allow this, and force you to serialize using JSON or some other drool?! :-D

                          Robust Services Core | Software Techniques for Lemmings | Articles
                          The fox knows many things, but the hedgehog knows one big thing.

                          <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                          <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                          H 1 Reply Last reply
                          0
                          • H honey the codewitch

                            The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                            Real programmers use butterflies

                            D Offline
                            D Offline
                            Daniel Pfeffer
                            wrote on last edited by
                            #13

                            [Program: Shoot in foot](http://www.personal.psu.edu/sxt104/program1.html)

                            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                            N F R 3 Replies Last reply
                            0
                            • H honey the codewitch

                              The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                              Real programmers use butterflies

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #14

                              I see no danger. Better than some other techniques.

                              1 Reply Last reply
                              0
                              • H honey the codewitch

                                The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                                Real programmers use butterflies

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                C# has been improving a lot in that area. You can take a `Span` of various types (some mostly-reasonable restrictions apply) and use `MemoryMarshal.AsBytes` on it to view it has a `Span`, then stash it in a file or whatever. It's nice. Actually paradoxically it's nicer than in C, because in C# you can actually control the layout of fields to whatever degree you need, so you can use this for file headers that have "unaligned" fields. C# is a better low level language than C.

                                Greg UtasG E 2 Replies Last reply
                                0
                                • H honey the codewitch

                                  The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.

                                  Real programmers use butterflies

                                  W Offline
                                  W Offline
                                  W Balboos GHB
                                  wrote on last edited by
                                  #16

                                  Exceptionally useful - you can do a cheap encryption by clever casting - or even more convenient, what might be considered an alias for casting: union And if one so chooses, passing ones data through a logical cuisinart is always appropriate. If you wish great power you must take great responsibility.       As always.

                                  Ravings en masse^

                                  "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                                  "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                                  H 1 Reply Last reply
                                  0
                                  • W W Balboos GHB

                                    Exceptionally useful - you can do a cheap encryption by clever casting - or even more convenient, what might be considered an alias for casting: union And if one so chooses, passing ones data through a logical cuisinart is always appropriate. If you wish great power you must take great responsibility.       As always.

                                    Ravings en masse^

                                    "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                                    "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                                    H Offline
                                    H Offline
                                    honey the codewitch
                                    wrote on last edited by
                                    #17

                                    I use unions sometimes, but i only needed the cast in two places in the code that inspired this post, and it was all it was ever going to need. :)

                                    Real programmers use butterflies

                                    W 1 Reply Last reply
                                    0
                                    • Greg UtasG Greg Utas

                                      Such a right-thinking person. :thumbsup: Are you implying that there are languages that don't allow this, and force you to serialize using JSON or some other drool?! :-D

                                      Robust Services Core | Software Techniques for Lemmings | Articles
                                      The fox knows many things, but the hedgehog knows one big thing.

                                      H Offline
                                      H Offline
                                      honey the codewitch
                                      wrote on last edited by
                                      #18

                                      something like that, yes. :-D

                                      Real programmers use butterflies

                                      1 Reply Last reply
                                      0
                                      • T The Other John Ingram

                                        I had a legacy program that had void****** as part of a sort routine. It worked, i didn't now how. The guy that wrote it was long gone and i spent a afternoon trying to figure out how it worked. In the end i left it alone.

                                        N Offline
                                        N Offline
                                        Nelek
                                        wrote on last edited by
                                        #19

                                        Member 14732673 wrote:

                                        In the end i left it alone.

                                        Really wise. Never touch a running system, unless you really know how to fix it :rolleyes: ;P :-D

                                        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                        T 1 Reply Last reply
                                        0
                                        • L Lost User

                                          C# has been improving a lot in that area. You can take a `Span` of various types (some mostly-reasonable restrictions apply) and use `MemoryMarshal.AsBytes` on it to view it has a `Span`, then stash it in a file or whatever. It's nice. Actually paradoxically it's nicer than in C, because in C# you can actually control the layout of fields to whatever degree you need, so you can use this for file headers that have "unaligned" fields. C# is a better low level language than C.

                                          Greg UtasG Offline
                                          Greg UtasG Offline
                                          Greg Utas
                                          wrote on last edited by
                                          #20

                                          Does it mandate the endianism and take the hit on non-compliant platforms, or is it still a problem for intersystem messages?

                                          Robust Services Core | Software Techniques for Lemmings | Articles
                                          The fox knows many things, but the hedgehog knows one big thing.

                                          <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                          <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups