C++ what is it good for?

Discussion in 'Programmer's Corner' started by jmoffat, Jan 19, 2013.

  1. jmoffat

    Thread Starter Member

    Jul 18, 2012
    42
    1
    As an electronics student years ago I had a semester of Pascal. Fast forward to today where I am in the process of finishing my associates degree. One of the courses I need to take is C++. I happened to mention to a programmer friend that I was taking C++. He couldn't believe that my school wanted me to learn such a antiquated language. Certainly there were many newer better languages. I of course didn't know what to say. So my question is what are the strengths of C++? What language would be better suited to an electronics student and why?
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,019
    Just plain C would be more useful if you plan on programming microcontroller. But any language will do. What is important is that you learn structure.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    I think your programming friend does not know what he's talking about.
    There are many languages still being used today and they all have their usefulness.
    If you are an electronics student my recommendation would be to learn ASM first followed by C.

    Pascal is a great place to begin, btw.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    "Experts" have been expecting the downfall of C/C++ since it was first written, yet variants of C today hold some 80% of market share.
     
  5. WBahn

    Moderator

    Mar 31, 2012
    17,788
    4,808
    Let's see. Here are some tidbits that I believe are still true:

    The Windows kernal is written in C. The Mac OS kernal is written in C. The Linux kernal is written in C. Most of the OS code above the kernals in each are either in C or C++. Other languages are making inroads, but not all that quickly.

    I believe it is still the case that more compilers are written in C than all other compilers combined. Most of the implementations of "modern languages" including Java and Python, are written in C++ if not C.

    Ask your friend was three languages he thinks you should know more than C/C++. Then do some searching and find out the market share each of them hold relative to C/C++ (or even Fortran and Cobol).

    For all of its many warts and shortcomings, C is still arguably the most powerful high level programming language out there -- and those warts and shortcomings are, for the most part, a direct consequence of that power. C gives the programmer unbelieveable levels of control, for a high level language, but it takes the attitude that any programmer that deserves that level of power is to assumed responsible enough to exercise it wisely and properly. In short, C is more than willing to give you plenty of rope with which to hang yourself -- and many/most programmers are not emotionally well-prepared to accept that.
     
    Last edited: Jan 19, 2013
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Pascal is a rubbish language.

    Q. How do you use arrays having variable size in Pascal?

    A. Easy. You allocate all available memory, and then create a library to allocate the arrays. Unfortunately you'll have to write converter functions to extract the data from the array.

    So it is not that this would not be possible in Pascal. You need 2 month time, 5000 lines code, and it will be 10x to 20x times slower than C.

    Alternatively, define an array as large as possible, and work on subsets. Your program code is then guaranteed to be ugly + non portable to anything.

    C has typecasting. Pascal does not. So you can't do it, or need to use an ugly workaround.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    C++ is often misused as label and it is misunderstood.
    C is included into C++.

    Many students and beginners only use C.

    C++ basically deals with objects which are spawned on the heap. Objects are function prototypes together with their data.

    On a microcontroller normally you would not have the memory available for that. Except some large 32bit chips.

    A standard for C++ is Visual Studio C++, which includes many language extensions, and libraries which are used together with Windows.

    If you want to program 8bit chips you only use C language compilers.

    It is important you understand the chip you use, and then you can program it in any language you wanted to.

    Pascal is not so much useful for learning because it insists too much on strong type expression. So if you learn it that way, you may think it has to be that way. Which is incorrect.

    C++ is mainly neccessary for writing programs which work in a Multitasking environment.

    If you only run one task, one program, there is not so much a point using C++.
     
  8. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Its not possible to explain the advantages and power of C/C++ in a single post ,so I will go in a very short way
    C/C++ is the most powerful language we have today.As already takao21203 has said "C is included into C++." ,when object oriented programming(OOP) was added in C it became C++,C is a structured based programming language ,with a very low level access i.e.. you can work with hardware with ease. On the other hand C++ provides OOP with which we can write complex application under operating system which provides complex function/API with ease.

    Many languages are actually abstracted from C++ ,like Java, C#(C Sharp) ,if you know C++ you will find Java and C# friendly the opposite is also same (upto a point).

    Industries most powerful and efficient language is C/C++ ,just check on internet about which language was used to develop some of the best software you know.

    Good Luck
     
  9. jmoffat

    Thread Starter Member

    Jul 18, 2012
    42
    1
    First off thanks to everyone for their replies and insight. I don't know where else I could go to get the kind of info you guys have given me.

    My take away from this is:

    1. Pascal was useful for introducing major concepts in programming and not too much else.

    2. Where an how C and C++ fits in with other languages.

    3. C is a structure based language that is well suited to access hardware at a low level. It is especially useful for playing with microprocessors.

    4. C++ works well for complex applications in Windows like environment that does multitasking.

    So it looks like I will be learning some C as well as C++.
     
  10. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    There are some things special to C language.

    It is sometimes called "Combined language", since it has assembler-like capabilities for instance pointer arithmetic.

    It can be obfuscated. Only a little for some reason, or even to a degree no one will be able to read the source code. The preprocessor is responsible for that.

    It is highly portable but this depends on the coding style.

    Many other languages are indeed C-type languages, such as Ruby (using different keywords but similar), PHP, and javascript. When you learn C, you can also use these easily.

    Compiled C is unforgiving, one wrong bit and the program may hang up. This is not neccessarily the case with scripted languages, or interpreted languages.

    Today's Windows C++ is at first compiled to MSIL, which is then compiled at runtime for a specific processor. So the direct disassembly interface is gone. 64bit Visual Studio does no longer offer disassembly capabilities.

    There are various predecessors to C such as BCPL the most noteable. BCPL somehow reminds on Pascal. They both derive from PL/1 a little- a very old language used by IBM in the 1950s.

    There are a few new BCPL sources these days but it is mainly used for esoteric and hobby purpose. It is uncomfortable like PASCAL but never has been adapted like PASCAL, for instance Turbo and Borland Pascal, and later, Delphi.

    Pascal has sometimes been called a "bondage" language.

    In the early 1980s almost nobody used Pascal or BASIC to develope console games. Either assembler or C compilers were used. C compilers were used professionally as soon as they emerged in the early 1980s.

    If you want more information, there are various webpages covering the history of the C language.

    C pointers at first may turn off people, but the basic pointers are not that difficult to use, at least, when you exactly know what you can do and want to do for instance on a controller chip.

    Particulary the syntax char *a is a bit misleading. Interestingly, char* a works equally.
     
  11. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I think their is a mistake with this statement.You are using Microsoft Visual C++.Net
    Any .Net (dot net) language is compiled into MSIL (Microsoft Intermediate Language) for example C# will compile its source code into MSIL.In case of C++,Microsoft has introduced (from 2003 I think) "Microsoft Visual C++.Net" which will compile its source code into MSIL.

    Microsoft Visual C/C++ compiler still compile its source code into native language for example for Intel P4 32 bits it will compile its source code into x86 opcodes.

    When we are talking about MSIL ,I should say this technique was first implemented by Java their source code is compiled into an intermediate language known as byte code,then this byte code is again compiled by runtime host i.e.. java runtime into native language.

    In case of MSIL .net runtime is the host which compiled the MSIL code to native language.

    You learn C ,then learn OOP ....thats how you learn C++

    Good Luck
     
  12. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Windows forms is "managed code". 32bit CPUs are no longer sold in shops for a few years now.
     
  13. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Not neccessarily. I have learned Windows C++ at first, then embedded assembler, and then embedded C.
     
  14. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186

    You are talking about the GUI forms designer and its available in C++.Net or any .Net language like C#,Visual Basic.Net .Windows form has nothing to do with the language it comes from Windows API (Application programming Interface),its built into our operating system, you can write your application in any language and the window will be the same as its provided by OS not the language.

    C++.Net is not C/C++,its just using the syntax of C/C++,so that C/C++ programmers do not have to learn new syntax ,and ready to program in .Net. .Net is a framework a bunch classes it have nothing to do with the language.

    In C/C++ we use Windows API to built window applications ,or some wrapper classes i.e.. framework like MFC ,wxWidgets ,etc

    As C/C++ is a native language it can use the OS API (Windows API) directly.


    I gave an example of x86 ,modern processors can be run in any mode i.e.. 32 bits or 64 bits.
     
    takao21203 likes this.
  15. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I didnt said its the only way,I myself first learned C#,then C++,C with x86 assembly.
     
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Yes you are right. But why should one learn one obscure supposed to be C++ when the real Windows C++ is so much different.

    Back 10 or 15 years ago there was a disassembly displayed, one could have used inline assembler if one wanted to, and now, it is gone.

    Not many people want to run in 32bit mode when 64bits are available.

    I think you need the 32bit Visual Studio install not just to define a 32bits compilation to use inline assembler and disassembly.

    If you build a command line executeable then maybe it is indeed compiled as native machine code, but anyway, you can not use 64bits inline assembler there is no such thing.

    I mean even if it is still available on older machines, you should not use it since maybe soon support for it will cease altogether.

    The latest trend is parallel computing on graphics card (not just for displaying graphics). A computation/rendering pipeline is used, not a classical opcode assembler. It does not well fit together with parallel computing, this is my opinion for one of the reasons why support for assembler was removed. Security is another reason.

    So if you take again PASCAL and it's way of dealing with a strong type system, and compare it to NVIDIAs latest parallel computing technology, it is really ages apart from each other.

    Teaching Pascal has some use to some people, but no longer has much to do with actual software. I consider it as misleading, irrelevant, and containing ballast. I spent some time with it myself- nowadays I would not want to touch it at all.
     
  17. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186


    Buddy I think (actually sure) you have never used C/C++ .Their is no obscure C++.
    What you are calling C++ is C++.Net a managed extensions for C++..

    Like Java Microsoft also wanted to be their applications platform independent, atleast over many variation of Windows platform, so they designed .Net framework and to program they created a new language called C#(C Sharp), but many windows programmers were C/C++ or Visual Basic programmers, so they created two new languages C++.Net and Visual Basic .Net they were different from the original C/C++ and Visual Basic, they were built upon .Net framework and just used the syntax of the original languages so that programmers do not have to learn new syntax. But inside they were a lot different like C++.Net compiles its code into MSIL but in case of C++ it compiles its code into current native language.

    C/C++ has never been obscured, at least till this date and it will be not in the coming years I don’t see any powerful language to replace it. Microsoft still provide C/C++ and its known as Microsoft Visual C++, and its still used by majority of programmers (I use it everyday),about the visual GUI form designer. Win API is so big and so many ways to implement it, its hard to make a visual GUI form designer for it ,in case of .Net its easy as its limited to .net classes but still limiting Win API we have some visual GUI form designer like Delphi ,C++ Builder and etc.

    To know latest about the language search C++ ISO Standards ,C++11 is the ISO C++ standard in 2011

    Remember C++.Net is not C++ and on 2013 never say C++ is obscured.

    http://en.wikipedia.org/wiki/Managed_Extensions_for_C%2B%2B


    We dont need the disassembly as the debugging is so powerful under Microsoft Visual C++ ,but still we do have disassembly...its not gone,you don't find it unless you use C++.


    It doesnt matters from programming point of view ,bits define the memory access the more bits the more memory you can access.


    I have no idea what you are talking,I think you got the whole concept wrong command line executeable have nothing to do with native machine code....
     
  18. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Ok maybe you don't use a 64 bit Windows + 64bit 3 core CPU + 64bit Visual Studio.

    When I write a program normally this will be a Windows Form.
     
  19. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I don't understand what you are trying to say...Compilers will take care of the bits stuff,its doesnt effect the language

    In native C/C++ you can also create Windows Forms Application ,look at the major windows softwares they all are written in native C/C++ I don't know any major windows software that is written in C++.Net ,yes I know a game its SWAT but again most/majority of 3D games are writen in native C/C++ as speed is a big factor in 3D games.
     
  20. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    There is no inline assembler and no disassembly this is a fact.

    I do not know if command line executeables are still native code.

    OK there is for instance a CLR console application. Which is managed.

    Games use DirectX normally and that has not much to do with x86 assembly.

    It depends on the Windows Version. Win7 or Win2008 = Windows Form.

    For Windows 8 it has again changed. DirectX is now integrated. And the Metro Framework is used.

    WinXP is mainly legacy. Some of the software still work, while other's don't.

    If you create a Win32 application with 64bit Visual studio, it is executed using the WoW32 layer (Windows on Windows).
     
Loading...