C or C++ for FOSS/linux? - Linux

This is a discussion on C or C++ for FOSS/linux? - Linux ; Hadron wrote: > "Chris F.A. Johnson" writes: > > On 2006-12-29, Sebastian 'lunar' Wiesner wrote: > >> Jan Panteltje typed > >> > > [snip] > >> > >> int *i = (int *) malloc (100*sizeof(int)); > >> > >> ...

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 31 of 31

Thread: C or C++ for FOSS/linux?

  1. Re: C or C++ for FOSS/linux?

    Hadron wrote:
    > "Chris F.A. Johnson" writes:
    > > On 2006-12-29, Sebastian 'lunar' Wiesner wrote:
    > >> Jan Panteltje typed
    > >>

    > > [snip]
    > >>
    > >> int *i = (int *) malloc (100*sizeof(int));
    > >>
    > >> I don't know much of C programming, but that is known to me as the way
    > >> you allocate an array of 100 integers on the heap in C.

    > >
    > > Wrong; it's:
    > >
    > > int *i = malloc (100*sizeof(int));


    Even better, make that

    int *i = malloc( 100 * sizeof *i );

    to avoid two changes if you need to change the type of 'i', one of
    wich you can easily forget;-)

    > > You should not cast the value returned by malloc; that can mask
    > > errors.


    > I have heard this before : but what errors can it mask?


    Casting the return value of malloc() keeps the compiler from
    complaining if you forgot to include where the
    prototype for malloc() is. That, in turn, will force the
    compiler to assume that malloc() returns an int and convert
    the return value to an int before casting it back, as requested
    by the explicit cast, to a pointer. This normally isn't an
    obvious problem on architectures where an int has the same size
    as a pointer and where data and addresses get returned via the
    same registers (like i368) but on other architectures this can
    lead to strange and hard to find bugs...

    Casting the return value of malloc() is only necessary if you
    compile with a C++ compiler - it isn't allowed to do it auto-
    matically.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  2. Re: C or C++ for FOSS/linux?

    Chris F.A. Johnson typed

    > On 2006-12-29, Sebastian 'lunar' Wiesner wrote:
    >> Jan Panteltje typed
    >>

    > [snip]
    >>
    >> int *i = (int *) malloc (100*sizeof(int));
    >>
    >> I don't know much of C programming, but that is known to me as the
    >> way you allocate an array of 100 integers on the heap in C.

    >
    > Wrong; it's:
    >
    > int *i = malloc (100*sizeof(int));
    >
    > You should not cast the value returned by malloc; that can mask
    > errors.


    Thanks for the correction. As I said, I have only little experience with
    C, because I try to avoid it whenever possible... I strongly dislike C.

    --
    Freedom is always the freedom of dissenters.
    (Rosa Luxemburg)

  3. Re: C or C++ for FOSS/linux?

    On a sunny day (Fri, 29 Dec 2006 21:07:55 +0000) it happened Rui Maciel
    wrote in <459583b3$0$28806$a729d347@news.telepac.pt>:

    >> If you want to provide any new origial functionality, then you will still
    >> have to code it.
    >> Coding in C is simpler and faster that is Stroussup language.

    >
    >Simpler and faster? Answer me this: when writing a C programmer what do you
    >do when you need a simple data structure like a linked list?


    I cut and paste from a previous coded linked list.
    It is written so generic that all I have to do is change some name that
    takes 5 seconds with my editor.
    If the structures making up the list need other members, then you will have to
    specify those in C++ too.
    That said I have seen people write linked lists in 5 lines in C in probably less
    then 5 seconds.
    Just that it took me much longer to understand their code :-)

    >>>> Qt 4 is the worst bloat I have seen in Linux since Linux 0.8 came out.


  4. Re: C or C++ for FOSS/linux?

    Jan Panteltje wrote:

    > I cut and paste from a previous coded linked list.
    > It is written so generic that all I have to do is change some name that
    > takes 5 seconds with my editor.
    > If the structures making up the list need other members, then you will
    > have to specify those in C++ too.
    > That said I have seen people write linked lists in 5 lines in C in
    > probably less then 5 seconds.
    > Just that it took me much longer to understand their code :-)


    So how can you possibly claim that "coding in C is so much simpler and
    faster" while at the same time you confess that each and every time you
    need to use trivial things like basic data structures you need to spend a
    considerable amount of time writing them by hand and debug them? Where's
    your "simplicity and quickness"? And we haven't even touched the algorithm
    side of it yet.

    The C programming language is a great tool, as C++ is. Both have their
    strengths and their weaknesses and therefore both are better suited to
    perform certain types of tasks. Therefore, this whole "language A is so
    awesome and so superior to language B in each and every possible way"
    discussion you are trying to have here is so braindead that it isn't even
    funny.

    Oh well... Trolls are simply trolls...


    Best regards
    Rui Maciel
    --
    Running Kubuntu 6.10 with KDE 3.5.5 and proud of it.
    jabber:rui_maciel@jabber.org

  5. Re: C or C++ for FOSS/linux?

    On a sunny day (Sat, 30 Dec 2006 12:30:37 +0000) it happened Rui Maciel
    wrote in <45965bf1$0$28777$a729d347@news.telepac.pt>:

    >Jan Panteltje wrote:
    >
    >> I cut and paste from a previous coded linked list.
    >> It is written so generic that all I have to do is change some name that
    >> takes 5 seconds with my editor.
    >> If the structures making up the list need other members, then you will
    >> have to specify those in C++ too.
    >> That said I have seen people write linked lists in 5 lines in C in
    >> probably less then 5 seconds.
    >> Just that it took me much longer to understand their code :-)

    >
    >So how can you possibly claim that "coding in C is so much simpler and
    >faster" while at the same time you confess that each and every time you
    >need to use trivial things like basic data structures you need to spend a
    >considerable amount of time writing them by hand and debug them?


    ?????
    You obviously do not knwo C, and never debug anythging in C++???????

    >Where's
    >your "simplicity and quickness"? And we haven't even touched the algorithm
    >side of it yet.


    Hell Stroussup loves ye.


    >The C programming language is a great tool, as C++ is.


    No C++ is a deficiency.

    >Both have their
    >strengths and their weaknesses and therefore both are better suited to
    >perform certain types of tasks. Therefore, this whole "language A is so
    >awesome and so superior to language B in each and every possible way"
    >discussion you are trying to have here is so braindead that it isn't even
    >funny.


    It was not _my_ discussion, and clearly it is the C++ devotees that feel
    hurt because they, in the deepest of their whatever it is, see C++ sucks.
    Tt sucks because it fails to be truly object oriented, is much too complicated
    for even a compilers, is huge typing overhead, makes no logic sense to me
    whatsoever, all this because Stroussup did not know how to program.

    This is my personal view, and you may have yours.
    You scream about trolls, but learn C first, even before C++, then you will
    see the futility of Stroussup language and how it makes software bloat.

    >Oh well... Trolls are simply trolls...


    Actually often I just prefer asm, as at least I talk to the chip.
    Try programming a micro controller in C++ pffffff.
    Bye


    >
    >Best regards
    >Rui Maciel





  6. Re: C or C++ for FOSS/linux?

    Hmmm... that's like asking whether a regular or phillips screw driver is
    better for turning screws. It depends on the screw you're trying to turn.

    The language is a tool. Use the correct one for the job. That has nothing to
    do with FOSS or Linux, by the way.

    Beowulf wrote:

    > C or C++, which is better to learn and improve upon for a goal of
    > contributing to open source projects, writing linux drivers, helping with
    > linux and FOSS in general?
    >



  7. Re: C or C++ for FOSS/linux?

    James McIninch writes:

    > Hmmm... that's like asking whether a regular or phillips screw driver is
    > better for turning screws. It depends on the screw you're trying to
    > turn.


    Tosh.

    Both are suitable for the same things. Had you said that in relation to
    choosing Javascript over C++ then fair enough.

    The answer is quite simple for his question : C since he mentioned
    device drivers and I guess some kernel work&/perusing.

    >
    > The language is a tool. Use the correct one for the job. That has nothing to
    > do with FOSS or Linux, by the way.
    >
    > Beowulf wrote:
    >
    >> C or C++, which is better to learn and improve upon for a goal of
    >> contributing to open source projects, writing linux drivers, helping with
    >> linux and FOSS in general?
    >>

    >


    --

  8. Re: C or C++ for FOSS/linux?


    Jan Panteltje wrote:
    > On a sunny day (Fri, 29 Dec 2006 17:09:40 +0100) it happened Sebastian 'lunar'
    > Wiesner wrote in :
    >
    > >int *i = (int *) malloc (100*sizeof(int));

    >
    > Right.


    I'm surprised to see Jan agree with that. The line
    above is how a C++ coder would allocate the space
    in C. It is more usually written:

    #define BUFSIZE 100
    ....
    int *i;
    i = malloc ( BUFSIZE * sizeof *i);

    (no cast, and sizeof is applied to the object rather than
    the object's type)

    --
    Bill Pursell


  9. Re: C or C++ for FOSS/linux?


    Jan Panteltje wrote:
    > On a sunny day (Fri, 29 Dec 2006 21:07:55 +0000) it happened Rui Maciel
    > wrote in <459583b3$0$28806$a729d347@news.telepac.pt>:
    >
    > >> If you want to provide any new origial functionality, then you will still
    > >> have to code it.
    > >> Coding in C is simpler and faster that is Stroussup language.

    > >
    > >Simpler and faster? Answer me this: when writing a C programmer what do you
    > >do when you need a simple data structure like a linked list?


    I do something like:

    #include

    myds_list L;
    int *x, y[1];
    L = myds_new_list(SIZE, 0, sizeof (int));
    *y=5;
    myds_list_append(L, y);
    *y=3;
    myds_list_append(L, y);
    x = myds_list_pop();

    OR use one of the many commonly available libraries that
    have list implementations, OR use one of the many macro
    packages that are available.

    There is no need to incorporate the data structures
    into the language, because there are plenty of libraries
    available that provide them. It is true that this requires
    the programmer and the maintainer to be familiar
    with the libraries, and this may make maintenance
    more difficult since the new maintainer needs to
    become familiar with the library, but I don't think that
    is a substantial issue.

    The list implementation that I've written in my data structures
    library is not ideal, but it serves 2 important purposes: I
    learned a lot writing it, and I am much more familiar
    with it than I am with those in the C++ STL. For simple
    operations, it out performs the C++ STL on all of the
    benchmarks that I've checked it against. And, when
    it doesn't do what I want, I can modify it much faster
    than I can modify those in the STL. There is no cut-and-paste
    involved in using it--but it does require that I add a -lmydl to my
    compile options. That doesn't strike me as too terribly
    burdensome.

    --
    Bill Pursell


  10. Re: C or C++ for FOSS/linux?

    On a sunny day (2 Jan 2007 10:10:27 -0800) it happened "Bill Pursell"
    wrote in
    <1167761427.884253.239140@h40g2000cwb.googlegroups. com>:

    >
    >Jan Panteltje wrote:
    >> On a sunny day (Fri, 29 Dec 2006 21:07:55 +0000) it happened Rui Maciel
    >> wrote in <459583b3$0$28806$a729d347@news.telepac.pt>:
    >>
    >> >> If you want to provide any new origial functionality, then you will still
    >> >> have to code it.
    >> >> Coding in C is simpler and faster that is Stroussup language.
    >> >
    >> >Simpler and faster? Answer me this: when writing a C programmer what do you
    >> >do when you need a simple data structure like a linked list?

    >
    >I do something like:
    >
    >#include
    >
    >myds_list L;
    >int *x, y[1];
    >L = myds_new_list(SIZE, 0, sizeof (int));
    >*y=5;
    >myds_list_append(L, y);
    >*y=3;
    >myds_list_append(L, y);
    >x = myds_list_pop();
    >
    >OR use one of the many commonly available libraries that
    >have list implementations, OR use one of the many macro
    >packages that are available.
    >
    >There is no need to incorporate the data structures
    >into the language, because there are plenty of libraries
    >available that provide them. It is true that this requires
    >the programmer and the maintainer to be familiar
    >with the libraries, and this may make maintenance
    >more difficult since the new maintainer needs to
    >become familiar with the library, but I don't think that
    >is a substantial issue.
    >
    >The list implementation that I've written in my data structures
    >library is not ideal, but it serves 2 important purposes: I
    >learned a lot writing it, and I am much more familiar
    >with it than I am with those in the C++ STL. For simple
    >operations, it out performs the C++ STL on all of the
    >benchmarks that I've checked it against. And, when
    >it doesn't do what I want, I can modify it much faster
    >than I can modify those in the STL. There is no cut-and-paste
    >involved in using it--but it does require that I add a -lmydl to my
    >compile options. That doesn't strike me as too terribly
    >burdensome.


    1 why I did not object to his malloc()? I understood he is not a C programmer.
    2 I agree with you here, it is important to know how the stuff works in detail,
    as in your case.
    Yes you need to look close at those libraries, not to difficult if you wrote
    those yourself.

    For me it is [all] about functionality, and indeed many languages can give the
    same functionality.
    Of all those languages I do however prefer the ones that let me know what
    sort of instructions the processor does.
    There is binary (yes I have programmed micro controller EPROMS in the long
    ago past with pencil and paper setting ones and zeros for machine instructions).
    Then there is ASM, and a good macro assembler with some libraries is better
    then some BASICs.
    Then there is C, and for drivers, OS related stuff close enough to the hardware
    and you can always use in line asm too.
    Then there are others like Lisp, on a different level.
    The higher levels (prolog etc) are interesting, but C is like bricks,
    you can build a small wall, or a castle with it, and it is 'sort of'
    portable, unlike asm and machine code.
    And there are C compilers for almost any processor or micro controller.

    In the end we should never forget (in spite of all the objections against
    'goto') that even C++ is translated to sequential code and 'goto' jumps.
    I like writing in ASM, especially for small micros, like PIC for example.
    To say 'hello world' takes only so few bytes :-) and in FPGA you can do
    it with gates and logic too, not even a processor needed.... design the
    UART in the process. (LCD driver as state machine I have).
    But where does the C++ programmer go with cout?
    I remember a converstation with my boss in the eighties about 'top down'
    and 'bottom up' approach.
    My view was, and still is, that you need to know the bricks to be able
    to build the castle.
    Bridges have fallen....

    You can do magic if you know the hardware, asm, C.
    Where others need tons of stuff.





  11. Re: C or C++ for FOSS/linux?

    Jan Panteltje wrote:
    > Coding in C is simpler and faster that is Stroussup language.


    Maybe. But, C++ and object-oriented programming is not about being
    faster, but about begin reusable and more maintainable. You invest more
    time initially, but in the long run it pays off since program is easier
    to maintain and extend.

    Well, at least, it should be - the problem is that mastering C++ syntax
    and mastering OO design are two very different things. Many people could
    say that they know C++, but if they don't understand how to use OO
    properly, you end-up with C-like program that took more time to write
    and is harder to maintain than its C equivalent.

    > Compiling a basic kernel with a lot of drivers and functionality takes less
    > then an hour on a Duron 950, so much less then Qt4.


    The problem is with GCC, not C++ itself. G++ is terribly slow. After
    trying out some free C++ compilers on Windows (Borland's or M$), it
    really is a pain to use G++. But, I do use it for everyday development.

    > I like to write things only once. After that it is no longer new territory.
    > Have not written a hex editor yet.


    I considered writing a quality ncurses hex editor, but don't have much
    time for it now.

    --
    Milan Babuskov
    http://njam.sourceforge.net
    http://swoes.blogspot.com

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2