The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Before structs were made

Last post 07-24-2008 7:31 AM by SenTree. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 07-23-2008 10:30 AM

    Before structs were made

    I know that struct hasn't existed forever, still, I want to know if code like this was common before it was created, or common when you use f2c to translate FORTRAN code to C...

    double dm5buf[ 32 ];                                          
    byte   *const m5buf          = (byte*)dm5buf;                 
    double *const SettlePrice    = (double*)((char*)m5buf      ); 
    double *const PoolValue      = (double*)((char*)m5buf +   8); 
    double *const DKFee          = (double*)((char*)m5buf +  16); 
    double *const OtherFee       = (double*)((char*)m5buf +  24); 
    double *const DKDays         = (double*)((char*)m5buf +  32); 
    
    just checking :)
    --
    "I, Fernando Wood, hereby declare our city a free and independent state to be named Tri-Insula!" -- Fernando Wood, Mayor of NYC, 1860-1862
  • 07-23-2008 10:49 AM In reply to

    Re: Before structs were made

    I've seen this used, but with sizeof() instead of hard-wired integer offsets...

  • 07-23-2008 10:52 AM In reply to

    Re: Before structs were made

    Structures predate f2c. According to Dennis Ritchie, structures were in place by 1973, and were pretty complete by the release of K&R in 1978.
  • 07-23-2008 1:39 PM In reply to

    Re: Before structs were made

     Seems like a fairly reasonable way to emulate a Fortran named COMMON block.  If I was porting Fortran code to C I would use a struct, but this is closer to the Fortran syntax. Wow, I do not miss those days of chasing variables into common blocks, only to find that another module used the same block, but with the variables named differently.

     The only time I have seen new code even remotely similar to that was with cross-platform code where devlopers were concerned about platform specific variations in the way structures were packed (and were not familiar enough with all the compilers involved to get the packing pragmas right).

    - dave 

  • 07-23-2008 6:32 PM In reply to

    • ZPedro
    • Not Ranked
    • Joined on 06-24-2008
    • Posts 3

    Re: Before structs were made

    Doesn't surprise me, since "As all Real Programmers know, the only useful data structure is the Array. Strings, Lists, Structures, Sets-- these are all special cases of arrays and can be treated that way just as easily without messing up your programming language with all sorts of complications." ( http://www.pbm.com/~lindahl/real.programmers.html ). ;)

  • 07-24-2008 3:41 AM In reply to

    Re: Before structs were made

    dmearns:

     The only time I have seen new code even remotely similar to that was with cross-platform code where devlopers were concerned about platform specific variations in the way structures were packed (and were not familiar enough with all the compilers involved to get the packing pragmas right).

    Concur. I use something similar in distributed embedded systems, not because I don't understand the packing pragmas, but because at least one of my compilers doesn't have any !.
  • 07-24-2008 4:19 AM In reply to

    Re: Before structs were made

    This code is also written by someone that has figured out that pointer arithmatic means that adding a number to a pointer gives different results depending on the type of the pointer (hence they have done a stupid cast to byte then to char then add) but they haven't realised that this will actually make thier code much easier!

    double dm5buf[ 32 ];                                          
    byte *const m5buf = (byte*)dm5buf;
    double *const SettlePrice = dm5buf;
    double *const PoolValue = dm5buf + 1;
    double *const DKFee = dm5buf + 2;
    double *const OtherFee = dm5buf + 3;
    double *const DKDays = dm5buf + 4;


    Linux is not a code base. Or a distro. Or a kernel. It's an attitude. And it's not about Open Source. It's about a bunch of people who still think vi is a good config UI.

    Notice: Phorm, and it's agents including ISPs collecting data on Phorm's behalf, are specifically forbidden from performing any processing or monitoring of the content of the above post. Hence, under the Regulation of Investigatory Powers Act 2000 any such attempt to profile this page by Phorm or it's agents is illegal.
  • 07-24-2008 6:13 AM In reply to

    Re: Before structs were made

    SenTree:
    dmearns:

     The only time I have seen new code even remotely similar to that was with cross-platform code where devlopers were concerned about platform specific variations in the way structures were packed (and were not familiar enough with all the compilers involved to get the packing pragmas right).

    Concur. I use something similar in distributed embedded systems, not because I don't understand the packing pragmas, but because at least one of my compilers doesn't have any !.
     

     

    If you're worried about cross-platform structure packing (e.g. for comms in a distributed system) then shouldn't you also be worried about things like endianness, which this approach doesn't address?

  • 07-24-2008 7:31 AM In reply to

    Re: Before structs were made

    Hatshepsut:

    SenTree:
    I use something similar in distributed embedded systems, not because I don't understand the packing pragmas, but because at least one of my compilers doesn't have any !.
     

    If you're worried about cross-platform structure packing (e.g. for comms in a distributed system) then shouldn't you also be worried about things like endianness, which this approach doesn't address?

    Absolutely. That's why I said 'something like', meaning the explicit indexing. My code does also address endianness, basically by assembling words from explicitly indexed bytes. No, it's not elegant, but I don't believe there is an elegant solution given the legacy constraints.
Page 1 of 1 (9 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems