Array

Discussion in 'C Programming' started by raghu, Jun 24, 2010.

  1. raghu

    raghu Guest

    What is the difference between
    char a[10];
    and
    typedef character char [10]
    character a;
     
    raghu, Jun 24, 2010
    #1
    1. Advertising

  2. raghu

    Eric Sosman Guest

    On 6/24/2010 12:38 PM, raghu wrote:
    > What is the difference between
    > char a[10];
    > and
    > typedef character char [10]
    > character a;


    One compiles, the other does not.

    Perhaps for the second you meant

    typedef char character[10]; // words reversed, ; added
    character a;

    If so, the only difference is the way you spelled your code:
    In both cases, `a' is an array of ten `char'.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jun 24, 2010
    #2
    1. Advertising

  3. On Thu, 24 Jun 2010, Eric Sosman wrote:

    > On 6/24/2010 12:38 PM, raghu wrote:
    >> What is the difference between
    >> char a[10];
    >> and
    >> typedef character char [10]
    >> character a;

    >
    > One compiles, the other does not.
    >
    > Perhaps for the second you meant
    >
    > typedef char character[10]; // words reversed, ; added
    > character a;
    >
    > If so, the only difference is the way you spelled your code:
    > In both cases, `a' is an array of ten `char'.


    A weakly related earlier thread ("How is const applied to a pointer
    declared in a function parameter"):

    http://groups.google.com/group/comp.lang.c/browse_thread/thread/466bf8ae666a4518/

    (I remembered it because of the array typedef, sorry if it's completely
    irrelevant.)

    lacos
     
    Ersek, Laszlo, Jun 24, 2010
    #3
  4. On 24 June, 17:38, raghu <> wrote:
    > What is the difference between
    > char a[10];
    > and
    > typedef character  char [10]
    > character a;


    even after your syntax errors are corrected it might be worth pointing
    out you hardly ever want an array to be hidden in a typedef
     
    Nick Keighley, Jun 28, 2010
    #4
  5. Nick Keighley <> writes:

    > On 24 June, 17:38, raghu <> wrote:
    >> What is the difference between
    >> char a[10];
    >> and
    >> typedef character  char [10]
    >> character a;

    >
    > even after your syntax errors are corrected it might be worth pointing
    > out you hardly ever want an array to be hidden in a typedef


    You may be right. I offer this because I've seen it -- I am in two
    minds about the value of it:

    typedef struct some_huge_structure a_thing[1];

    The result is an object type ('a_thing') that can be declared and
    initialised almost like any other:

    a_thing my_thing = {0}, my_result;

    but which gets passed as a pointer without any special action:

    thing_function(my_thing, my_result);

    Apart from being "tricksy" it suffers from the problem that you can't
    return a_thing from a function, but when an API uses the return for
    error signalling, this is less of a issue.

    --
    Ben.
     
    Ben Bacarisse, Jun 28, 2010
    #5
  6. raghu

    raghu Guest

    On Jun 24, 9:53 am, Eric Sosman <> wrote:
    > On 6/24/2010 12:38 PM, raghu wrote:
    >
    > > What is the difference between
    > > char a[10];
    > > and
    > > typedef character  char [10]
    > > character a;

    >
    >      One compiles, the other does not.
    >
    >      Perhaps for the second you meant
    >
    >         typedef char character[10];  // words reversed, ; added
    >         character a;
    >
    > If so, the only difference is the way you spelled your code:
    > In both cases, `a' is an array of ten `char'.
    >
    > --
    > Eric Sosman
    >


    your are right. I was in a hurry. Sorry about that.
     
    raghu, Jul 1, 2010
    #6
  7. raghu

    Eric Sosman Guest

    On 6/30/2010 10:29 PM, raghu wrote:
    > On Jun 24, 9:53 am, Eric Sosman<> wrote:
    >> On 6/24/2010 12:38 PM, raghu wrote:
    >>
    >>> What is the difference between
    >>> char a[10];
    >>> and
    >>> typedef character char [10]
    >>> character a;

    >>
    >> One compiles, the other does not.
    >>
    >> Perhaps for the second you meant
    >>
    >> typedef char character[10]; // words reversed, ; added
    >> character a;
    >>
    >> If so, the only difference is the way you spelled your code:
    >> In both cases, `a' is an array of ten `char'.

    >
    > your are right. I was in a hurry. Sorry about that.


    Perhaps your next hasty, sloppy question will get a hasty,
    sloppy answer.

    Sorry about that.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jul 1, 2010
    #7
    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. Daniel
    Replies:
    1
    Views:
    1,054
    Kevin Collins
    Aug 14, 2003
  2. S300
    Replies:
    4
    Views:
    22,004
    Roedy Green
    Aug 19, 2003
  3. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    496
    David RF
    Sep 3, 2009
  4. Tom
    Replies:
    3
    Views:
    213
    salsablr
    Dec 20, 2004
  5. Tuan  Bui
    Replies:
    14
    Views:
    478
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page