Re: [LONG] help with old source code from book

Discussion in 'C Programming' started by Phil Carmody, Aug 3, 2009.

  1. Phil Carmody

    Phil Carmody Guest

    superpollo <> writes:
    > Gordon Burditt wrote:
    >>> i was browsing an old book about image processing in C, and i was
    >>> not able to compile most of the source code given there.

    >>
    >> For starters, how about including the command line to compile the
    >> code that you tried, and exact copies of the error message(s) you got
    >> when you used it? Did it have anything to do with there being no
    >> <alloc.h> header file? Did you install a C compiler?


    > ok.
    >
    > under linux with gcc i tried:
    >
    > $ gcc LIST2_1.C


    That compiles as C++, as gcc annoyingly thinks it knows better
    than you what type of language a file is written in based on the
    name.

    > [...] iplib.c
    > In file included from /usr/include/c++/3.3/backward/alloc.h:46,

    ^^^^ that should have been a clue.
    > from LIST2_1.C:10:
    > /usr/include/c++/3.3/backward/backward_warning.h:32:2: warning:

    ^^^^ and that.
    > #warning This file includes at least one deprecated or antiquated
    > header. Please consider using one of the 32 headers found in section
    > 17.4.1.2 of the C++ standard. Examples include substituting the <X>

    ^^^^^^^^^^^^ as should that.

    Firstly ensure that you're actually invoking a C compiler, then
    we can help more.

    Phil
    --
    If GML was an infant, SGML is the bright youngster far exceeds
    expectations and made its parents too proud, but XML is the
    drug-addicted gang member who had committed his first murder
    before he had sex, which was rape. -- Erik Naggum (1965-2009)
     
    Phil Carmody, Aug 3, 2009
    #1
    1. Advertising

  2. Phil Carmody

    Nobody Guest

    On Mon, 03 Aug 2009 09:48:47 +0300, Phil Carmody wrote:

    >> under linux with gcc i tried:
    >>
    >> $ gcc LIST2_1.C

    >
    > That compiles as C++, as gcc annoyingly thinks it knows better
    > than you what type of language a file is written in based on the
    > name.


    That's not really fair. If you tell gcc what language it is with e.g.
    "-x c" or "-x c++", it won't question it. If you don't tell it, it will
    auto-detect it, based upon well-defined rules.

    It isn't gcc's fault that someone (CFront?) thought that using ".C" for
    C++ source files would be a good idea.

    If you give it a .C file and don't specify the language, what's the
    alternative?

    Analysing the file won't help if it has been written to be valid as both C
    and C++ (I know of C projects whose coding rules state that the code
    should compile with a C++ compiler).

    Moreso if the code uses "#ifdef __cplusplus ... #else ... #endif".

    Nowadays, assuming that it's a C file with the wrong case might be correct
    more often than assuming that it's an ancient C++ file. But if the case of
    the source filename is wrong, chances are that the case of any associated
    headers is also wrong, so it isn't going to compile regardless.
     
    Nobody, Aug 3, 2009
    #2
    1. Advertising

  3. Phil Carmody

    Phil Carmody Guest

    Nobody <> writes:
    > On Mon, 03 Aug 2009 09:48:47 +0300, Phil Carmody wrote:
    >
    >>> under linux with gcc i tried:
    >>>
    >>> $ gcc LIST2_1.C

    >>
    >> That compiles as C++, as gcc annoyingly thinks it knows better
    >> than you what type of language a file is written in based on the
    >> name.

    >
    > That's not really fair. If you tell gcc what language it is with e.g.
    > "-x c" or "-x c++", it won't question it. If you don't tell it, it will
    > auto-detect it, based upon well-defined rules.


    Before they decided to confuse everyone, gcc would invoke the C compiler,
    and g++ would invoke the C++ compiler. Which, as they are different
    compilers for different languages, makes perfect sense.

    > It isn't gcc's fault that someone (CFront?) thought that using ".C" for
    > C++ source files would be a good idea.
    >
    > If you give it a .C file and don't specify the language, what's the
    > alternative?


    I'd say that depends on which compiler you've invoked. Having one
    binary called gcc and another binary called g++, and invoking whichever
    one is appropriate for the source language seems to be a pretty good
    way of making sure it knows what language your source file is.

    Perhaps I'm a luddite, but I like it that way.

    Phil
    --
    If GML was an infant, SGML is the bright youngster far exceeds
    expectations and made its parents too proud, but XML is the
    drug-addicted gang member who had committed his first murder
    before he had sex, which was rape. -- Erik Naggum (1965-2009)
     
    Phil Carmody, Aug 3, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    709
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,223
    Peter Shaggy Haywood
    Sep 20, 2005
  3. *Prot3anThr3ad*

    old repository for old C++ source code

    *Prot3anThr3ad*, Sep 29, 2006, in forum: C++
    Replies:
    6
    Views:
    390
    *Prot3anThr3ad*
    Oct 2, 2006
  4. Mug
    Replies:
    4
    Views:
    410
    Beej Jorgensen
    Aug 1, 2009
  5. Mug
    Replies:
    2
    Views:
    366
    Nobody
    Aug 1, 2009
Loading...

Share This Page