Thread: Converting COBOL to C

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Subsonics View Post
    It does however include far easier to use, and safer string handling functions. And you could potentially choose just a small subset of C++ and ignore the rest (even the OOP stuff).
    In your opinion...

  2. #17
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by CommonTater View Post
    In your opinion...
    Look at the following code, does it contradict your 'opinion' ? It is quite easy to forget most extraneous stuff.
    Code:
    #include<cstdio>
    #include<cstring>
    #include<string>
    using namespace std;
    int main()
    {
        string foo("Manasij");
        //Do whatever you like with foo
        printf("%s",foo.c_str());
        return 0;
    }

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by manasij7479 View Post
    Look at the following code, does it contradict your 'opinion' ?
    Code:
    #include<cstdio>
    #include<cstring>
    #include<string>
    using namespace std;
    int main()
    {
        string foo("Manasij");
        //Do whatever you like with foo
        printf("%s",foo.c_str());
        return 0;
    }
    This is not the time to defend or attack your favorite language... it does nothing to help the OP...

  4. #19
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by CommonTater View Post
    This is not the time to defend or attack your favorite language... it does nothing to help the OP...
    I think it could help. String handling is 'much' easier and intuitive in C++ than in C, and he has already said that he would be willing to experiment with both.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok, then... you carry on with him and I'll go make supper...

    (We do this A LOT... someone asks a question and invariably it degenerates into the regulars here debating amongst themselves... I'm trying very hard not to get caught up in that anymore).

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > However, whats the general consensus about the portability of C++.
    Well you haven't listed any machines where C++ would not be available.
    With the exception of very low spec embedded micro processors, C++ is just as widely available as C is.


    > 01 ASCIINUM PIC ---,---,--9.99 VALUE ZERO. *> 14 byte ASCII data.
    > 01 DECINUM PIC S9(14)V(4) COMP VALUE 0. *> 64 bit binary data.
    > MOVE DECINUM TO ASCIINUM.
    > MOVE ASCIINUM TO DECINUM .
    > Should I look into the string class from C++?
    Or even making your own classes called ASCIINUM and DECINUM (built on top of whatever you feel like).

    Then if you choose to overload assignment operator, you can literally do
    myDecinumVar = myAsciinumVar;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    With C++ you have to use the same compiler because of C++ Name Mangling makes an DLL built for Compiler A not work with Compiler B.
    The OP original post said he wanted better than that.

    Tim S.

  8. #23
    Registered User
    Join Date
    Sep 2011
    Posts
    10
    Quote Originally Posted by CommonTater View Post
    (My opinion only...) C++ is a monster, that I found to be heavily cluttered with stuff I won't likely use and a programming paradigm that simply does not in any way resemble how my mind works. Of course you may find a home in it... It's really up to you..
    Exactly what I feared, but can C++ be written to be portable?

    Quote Originally Posted by CommonTater View Post
    It would, I think, be a serious error in judgement to try to make the new thing work just like the old thing... most often when doing that the new thing ends up getting broken... (Hense my earlier suggestion of a rewrite, not a mere translation).
    Right, I want a re-write, the question is what to write?

    Quote Originally Posted by Subsonics View Post
    It does however include far easier to use, and safer string handling functions. And you could potentially choose just a small subset of C++ and ignore the rest (even the OOP stuff).
    OK! So, using C++ instead of staying with standard C would allow easier and safer string handling.

    I've got allot of info from you guys, and so I need to do some reading, writing, and testing. I will post back my progress, and thanks so much to all!

    --
    Ye Old Geek

  9. #24
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by OldGeek View Post
    Exactly what I feared, but can C++ be written to be portable?
    Yes. You will probably have fewer portability problems with C++ programs... DLLs as pointed out might be another matter. There you will have to expose interfaces that are compatible with C, C++ and others... otherwise you are restricting yourself to C++ executables. You may want to give some thought to making your DLLs in C (C++ can work with them easily) and doing your main executables in C++ (where you can mess with your safer strings).

    Right, I want a re-write, the question is what to write?
    Oh you know, the usual stuff... keywords, brackets, braces, functions etc.

    OK! So, using C++ instead of staying with standard C would allow easier and safer string handling.
    Yes and No... The C++ Strings library is easier to use, but these are not standard C strings and will require conversion (eg. Mystring.cstring) every time you talk to anything but your own C++ libraries. In my opinion the benefit is dubious at best... (But I've been wrong before )

    I've got allot of info from you guys, and so I need to do some reading, writing, and testing. I will post back my progress, and thanks so much to all!
    Well don't be a stranger... it's good to have people here with some programming background.

  10. #25
    Registered User
    Join Date
    Sep 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    > However, whats the general consensus about the portability of C++.
    Well you haven't listed any machines where C++ would not be available.
    With the exception of very low spec embedded micro processors, C++ is just as widely available as C is.
    Sounds good!

    > Should I look into the string class from C++?
    Quote Originally Posted by Salem View Post
    Or even making your own classes called ASCIINUM and DECINUM (built on top of whatever you feel like).

    Then if you choose to overload assignment operator, you can literally do
    myDecinumVar = myAsciinumVar;
    Looks like what I need to do, but overloading seems non-standard, or maybe I'm overloaded ;-)
    Thanks.

  11. #26
    Registered User
    Join Date
    Sep 2011
    Posts
    10
    Quote Originally Posted by CommonTater View Post
    (We do this A LOT... someone asks a question and invariably it degenerates into the regulars here debating amongst themselves... I'm trying very hard not to get caught up in that anymore).
    This is good, but also I understand not wanting to get caught up in it, as it does exhaust lots of energy. Although the more you guys debate the issues the more I benefit

    Years ago, I worked with a group of guys for about ten years doing software development, and we would get into lots of heated debate, and knock-down drag-out arguments. On rare occasion one of us would take off in the middle of the day, swearing to never return, only to be back the next morning as if nothing happened. More often it was just the normal yelling and cussing and name calling, then a good time at lunch together, then back it again for the afternoon round.

    Bottom line -- debate, arguing, and even some name calling is deemed good and useful in my eyes anyway, as long as no one gets hurt. This is how we ring it out, and get to the truth.

  12. #27
    Registered User
    Join Date
    Sep 2011
    Posts
    10
    I need to build .dll's and .so libraries, and they must be callable from multiple other languages, so it appears that standard C is the only option to meet those requirements.

  13. #28
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Bottom line -- debate, arguing, and even some name calling is deemed good and useful in my eyes anyway, as long as no one gets hurt. This is how we ring it out, and get to the truth.
    Wheelll, that might be how YOU do it ...

    I know. It's just that you can get the same or better information by getting 6 independent replies to your inquiries. I'm just trying not to get (you) caught up in a cycle of asking a question then watching the fight...

  14. #29
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by OldGeek View Post
    I need to build .dll's and .so libraries, and they must be callable from multiple other languages, so it appears that standard C is the only option to meet those requirements.
    Investigate more... but I believe so.

  15. #30
    Registered User
    Join Date
    Sep 2011
    Posts
    10
    Quote Originally Posted by CommonTater View Post
    Investigate more... but I believe so.
    Well I've built a rather large header file, libvue3.h
    re-writing all the Cobol Record layouts into C struct's.
    as well as the COBOL linkage into C vars and struct's
    I also added all the main prototypes into the header file, with the necessary includes.

    Then started on the libvue3.c with the necessary includes, and functions based on the prototypes, which were based on the COBOL ENTRY routines.

    It took awhile, testing and changing parm/arg linkage, but it now compiles and links to a test COBOL application program. All parms are being successfully passed to the C library from the Cobol app and back again. Debug fprintf's actually prove this...

    Now that the base structure of the new library actually compiles and links, I need to write the guts of each function, all in standard C ofcourse.

    Thanks again for all you input!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cobol?!
    By cyberCLoWn in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-23-2003, 06:23 PM
  2. Cobol!? Why!?
    By carrja99 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-08-2003, 02:44 PM
  3. Cobol
    By ammar in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 02-20-2003, 12:23 PM
  4. cobol
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-03-2002, 12:02 AM
  5. Cobol
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-19-2001, 10:50 AM