To: Richard Heathfield

Discussion in 'C Programming' started by Bill Cunningham, Aug 15, 2009.

  1. I made a minor adjustment to your flip function from a previous post. I
    tried to compile into an .o file and got these errors. What have I done now?

    Thanks

    void flip(unsigned char *c, size_t len)
    {
    while(len--)
    {
    *b = ~*b;
    ++b;
    }
    }

    v.c:1: parse error before "size_t"
    v.c: In function `flip':
    v.c:3: `len' undeclared (first use in this function)
    v.c:3: (Each undeclared identifier is reported only once
    v.c:3: for each function it appears in.)
    v.c:5: `b' undeclared (first use in this function)

    Bill
     
    Bill Cunningham, Aug 15, 2009
    #1
    1. Advertising

  2. Re: Richard Heathfield

    "Bill Cunningham" <> wrote in message
    news:4a8706e5$0$23768$...
    > I made a minor adjustment to your flip function from a previous post. I
    > tried to compile into an .o file and got these errors. What have I done
    > now?
    >
    > Thanks
    >
    > void flip(unsigned char *c, size_t len)
    > {
    > while(len--)
    > {
    > *b = ~*b;
    > ++b;
    > }
    > }
    >
    > v.c:1: parse error before "size_t"
    > v.c: In function `flip':
    > v.c:3: `len' undeclared (first use in this function)
    > v.c:3: (Each undeclared identifier is reported only once
    > v.c:3: for each function it appears in.)
    > v.c:5: `b' undeclared (first use in this function)
    >
    > Bill


    Oh god. Now I really feel stupid. I need to think more before I post. I
    need to include stdio.h ! I think this might be the only problem.

    Bill
     
    Bill Cunningham, Aug 15, 2009
    #2
    1. Advertising

  3. Bill Cunningham <> wrote:
    >v.c:1: parse error before "size_t"


    The error "parse error before yyy" often tends to mean "I don't know
    what yyy is."

    In this case, size_t isn't a "built-in" type; it comes from a header
    file. Try #include <stddef.h> to define it.

    -Beej
     
    Beej Jorgensen, Aug 15, 2009
    #3
  4. "Beej Jorgensen" <> wrote in message
    news:h672nm$e8i$-september.org...

    > In this case, size_t isn't a "built-in" type; it comes from a header
    > file. Try #include <stddef.h> to define it.


    Ok I see. Thanks. But what do you mean in this case?

    Bill
     
    Bill Cunningham, Aug 15, 2009
    #4
  5. Bill Cunningham

    mark Guest

    On Sat, 15 Aug 2009 15:05:36 -0400, Bill Cunningham wrote:

    > I made a minor adjustment to your flip function from a previous post. I
    > tried to compile into an .o file and got these errors. What have I done now?
    >
    > Thanks
    >
    > void flip(unsigned char *c, size_t len)
    > {
    > while(len--)
    > {
    > *b = ~*b;
    > ++b;
    > }
    > }
    >
    > v.c:1: parse error before "size_t"
    > v.c: In function `flip':
    > v.c:3: `len' undeclared (first use in this function)
    > v.c:3: (Each undeclared identifier is reported only once
    > v.c:3: for each function it appears in.)
    > v.c:5: `b' undeclared (first use in this function)
    >
    > Bill


    hey bill

    try putting

    typedef unsigned long long size_t;

    at the beginning of the file.
     
    mark, Aug 15, 2009
    #5
  6. On Sat, 15 Aug 2009 22:17:38 +0100, mark <> wrote:

    >On Sat, 15 Aug 2009 15:05:36 -0400, Bill Cunningham wrote:
    >
    >> I made a minor adjustment to your flip function from a previous post. I
    >> tried to compile into an .o file and got these errors. What have I done now?
    >>
    >> Thanks
    >>
    >> void flip(unsigned char *c, size_t len)
    >> {
    >> while(len--)
    >> {
    >> *b = ~*b;
    >> ++b;
    >> }
    >> }
    >>
    >> v.c:1: parse error before "size_t"
    >> v.c: In function `flip':
    >> v.c:3: `len' undeclared (first use in this function)
    >> v.c:3: (Each undeclared identifier is reported only once
    >> v.c:3: for each function it appears in.)
    >> v.c:5: `b' undeclared (first use in this function)
    >>
    >> Bill

    >
    >hey bill
    >
    >try putting
    >
    >typedef unsigned long long size_t;
    >
    >at the beginning of the file.


    Proof positive that not all the advice you receive on Usenet is worth
    following.

    --
    Remove del for email
     
    Barry Schwarz, Aug 15, 2009
    #6
  7. Bill Cunningham

    mark Guest

    On Sat, 15 Aug 2009 14:27:39 -0700, Barry Schwarz wrote:
    > On Sat, 15 Aug 2009 22:17:38 +0100, mark <> wrote:
    >
    >>On Sat, 15 Aug 2009 15:05:36 -0400, Bill Cunningham wrote:
    >>
    >>> I made a minor adjustment to your flip function from a previous post. I
    >>> tried to compile into an .o file and got these errors. What have I done now?
    >>>
    >>> Thanks
    >>>
    >>> void flip(unsigned char *c, size_t len)
    >>> {
    >>> while(len--)
    >>> {
    >>> *b = ~*b;
    >>> ++b;
    >>> }
    >>> }
    >>>
    >>> v.c:1: parse error before "size_t"
    >>> v.c: In function `flip':
    >>> v.c:3: `len' undeclared (first use in this function)
    >>> v.c:3: (Each undeclared identifier is reported only once
    >>> v.c:3: for each function it appears in.)
    >>> v.c:5: `b' undeclared (first use in this function)
    >>>
    >>> Bill

    >>
    >>hey bill
    >>
    >>try putting
    >>
    >>typedef unsigned long long size_t;
    >>
    >>at the beginning of the file.

    >
    > Proof positive that not all the advice you receive on Usenet is worth
    > following.


    echo '#include <stdio.h>' | gcc -x c -E - | wc -l
    748

    why slow down compilation by including massive complex headers just to get
    one typedef.
     
    mark, Aug 15, 2009
    #7
  8. mark <> wrote:
    > On Sat, 15 Aug 2009 15:05:36 -0400, Bill Cunningham wrote:


    > > I made a minor adjustment to your flip function from a previous post. I
    > > tried to compile into an .o file and got these errors. What have I done now?
    > > void flip(unsigned char *c, size_t len)
    > > {
    > > while(len--)
    > > {
    > > *b = ~*b;
    > > ++b;
    > > }
    > > }
    > >
    > > v.c:1: parse error before "size_t"
    > > v.c: In function `flip':
    > > v.c:3: `len' undeclared (first use in this function)
    > > v.c:3: (Each undeclared identifier is reported only once
    > > v.c:3: for each function it appears in.)
    > > v.c:5: `b' undeclared (first use in this function)


    > try putting
    > typedef unsigned long long size_t;
    > at the beginning of the file.


    I don't think that's a very good advice. First of all 'unsigned
    long long' may not even exist on Bill's machine. And then why
    define it yourself when the compiler rather likely comes with
    <stddef.h> that already defines 'size_t' (written by people
    that probably know a lot more about the machine than me, you or
    Bill)? (Or Bill would be using a very outdated compiler - but
    that would, at the same time, significantly reduce his chances
    of having a 'unsigned long long' type.)

    And, BTW, concerning the error message:

    > > v.c:5: `b' undeclared (first use in this function)


    There's an argument of the function with the name 'c' and I
    strongly suspect that the use of 'b' within the function should
    be replaced by using this 'c' variable...

    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
     
    Jens Thoms Toerring, Aug 15, 2009
    #8
  9. "pete" <> wrote in message
    news:...

    > He means that size_t is not a keyword,
    > the way that unsigned and char are.
    >
    > unsigned and char are part of the C language proper,
    > meaning that no headers are needed
    > in order to use those words in C code.
    >
    > size_t is a feature of the standard library.
    > size_t is defined in <stddef.h>
    > and the definition of size_t is also duplicated
    > in many other headers, like <stdio.h>.
    >

    I wondered about that because I used printf and sizeof with just stdio.h
    defined and printf said "4" bytes without stddef.h.

    Bill
     
    Bill Cunningham, Aug 15, 2009
    #9
  10. Bill Cunningham

    Old Wolf Guest

    On Aug 16, 9:36 am, mark <> wrote:
    > echo '#include <stdio.h>' | gcc -x c -E - | wc -l


    bash: gcc: command not found

    > why slow down compilation by including massive complex headers just to get
    > one typedef.


    On my system, the relevant header has:
    typedef unsigned int size_t;

    Applying your "version" would just cause a cascade of errors.
     
    Old Wolf, Aug 16, 2009
    #10
  11. Bill Cunningham

    mark Guest

    On Sat, 15 Aug 2009 16:54:34 -0700, Old Wolf wrote:
    > On Aug 16, 9:36 am, mark <> wrote:
    >> echo '#include <stdio.h>' | gcc -x c -E - | wc -l

    >
    > bash: gcc: command not found
    >
    >> why slow down compilation by including massive complex headers just to get
    >> one typedef.

    >
    > On my system, the relevant header has:
    > typedef unsigned int size_t;
    >
    > Applying your "version" would just cause a cascade of errors.


    yes of course, if your using a legacy 32-bit operating system then you
    need a different typedef.
     
    mark, Aug 16, 2009
    #11
  12. Bill Cunningham

    Flash Gordon Guest

    mark wrote:
    > On Sat, 15 Aug 2009 16:54:34 -0700, Old Wolf wrote:
    >> On Aug 16, 9:36 am, mark <> wrote:
    >>> echo '#include <stdio.h>' | gcc -x c -E - | wc -l

    >> bash: gcc: command not found
    >>
    >>> why slow down compilation by including massive complex headers just to get
    >>> one typedef.

    >> On my system, the relevant header has:
    >> typedef unsigned int size_t;
    >>
    >> Applying your "version" would just cause a cascade of errors.

    >
    > yes of course, if your using a legacy 32-bit operating system then you
    > need a different typedef.


    Or a non-legacy 32 bit system, or a non-legacy 16 bit system, or the
    next generation 128 bit system...

    There really is no good reason not to include the an appropriate header,
    then you don't have to worry about it as it will always be correct. As
    mentioned by someone else, one of the possible appropriate headers is
    not massive.
    --
    Flash Gordon
     
    Flash Gordon, Aug 17, 2009
    #12
  13. mark <> writes:
    > On Sat, 15 Aug 2009 16:54:34 -0700, Old Wolf wrote:
    >> On Aug 16, 9:36 am, mark <> wrote:
    >>> echo '#include <stdio.h>' | gcc -x c -E - | wc -l

    >>
    >> bash: gcc: command not found
    >>
    >>> why slow down compilation by including massive complex headers just to get
    >>> one typedef.

    >>
    >> On my system, the relevant header has:
    >> typedef unsigned int size_t;
    >>
    >> Applying your "version" would just cause a cascade of errors.

    >
    > yes of course, if your using a legacy 32-bit operating system then you
    > need a different typedef.


    No, all you need is "#include <stddef.h>", and your code can work
    properly without modification on *any* conforming system.

    The true cost of "#include <stdio.h>" is not the number of lines
    it causes the compiler to process, it's the actual time (and other
    resources) it takes. I think you'll find the real cost is trivial.
    If you don't believe me, measure it.

    On the other hand, the cost of re-inventing the wheel by declaring
    size_t yourself rather than relying on the implementation's
    declaration can be huge. In the best case, it costs programmer
    time (not just computer time) to modify the source every time it's
    recompiled on a different system, or to confirm that the existing
    definition is correct. How? Probably by examining the system's
    stddef.h header -- if you can find it. How long will it take
    you to find it, to load it into your editor, to follow any macro
    expansions and typedefs it might depend on, and to be sure you've
    gotten it right? Compare this to the time it takes your compiler
    to process it.

    And suppose you've written your own declaration for size_t, and then
    later you decide you want to do some I/O so you add "#include
    <stdio.h>". Now you have two declarations for size_t.

    (I'm surprised to discover that gcc doesn't complain about this:

    #include <stddef.h> typedef unsigned int size_t;

    where <stddef.h> happens to typedef size_t as unsigned int; as far as
    I can tell by reading the standard, that's a constraint violation.)

    Others in this thread have made rather mild comments about your
    advice to declare:

    typedef unsigned long long size_t;

    I'll state it more strongly: that's among the worst C advice I've
    seen.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 17, 2009
    #13
  14. Bill Cunningham

    Flash Gordon Guest

    Keith Thompson wrote:
    > mark <> writes:


    <snip>

    > I'll state it more strongly: that's among the worst C advice I've
    > seen.


    Well, considering the advice was directed to Bill it's probably been
    forgotten already.
    --
    Flash Gordon
     
    Flash Gordon, Aug 17, 2009
    #14
  15. On 17 Aug 2009 at 20:20, Keith Thompson wrote:
    > Probably by examining the system's stddef.h header -- if you can find
    > it. How long will it take you to find it, to load it into your
    > editor, to follow any macro expansions and typedefs it might depend
    > on, and to be sure you've gotten it right?


    Keith, Keith, Keith, I'm disappointed in you.

    Imagine you of all people falling into the classic clc gotcha of making
    the cavalier assumption that stddef.h is a file, and susceptible to
    processing with an "editor"!
     
    Antoninus Twink, Aug 17, 2009
    #15
    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. Replies:
    12
    Views:
    659
  2. Malcolm McLean

    Richard Heathfield's personal threads.

    Malcolm McLean, Nov 9, 2007, in forum: C Programming
    Replies:
    52
    Views:
    1,210
    Christopher Benson-Manica
    Nov 21, 2007
  3. Tomás Ó hÉilidhe

    [OFF-TOPIC] Animosity on the part of Mr Richard Heathfield

    Tomás Ó hÉilidhe, Dec 13, 2008, in forum: C Programming
    Replies:
    113
    Views:
    2,063
    Richard Bos
    Dec 22, 2008
  4. Anonymous

    Animosity on the part of Mr Richard Heathfield

    Anonymous, Dec 14, 2008, in forum: C Programming
    Replies:
    6
    Views:
    406
    CBFalconer
    Dec 21, 2008
  5. Borked Pseudo Mailed

    Animosity on the part of Mr Richard Heathfield

    Borked Pseudo Mailed, Dec 14, 2008, in forum: C Programming
    Replies:
    0
    Views:
    242
    Borked Pseudo Mailed
    Dec 14, 2008
Loading...

Share This Page