Re: char s[] = "asdf" and extern char *s in separate files

Discussion in 'C Programming' started by Newsgroup - Ann, Jul 5, 2003.

  1. Thank you. The information is pretty helpful. Sorry I did not check the FAQ
    first, it's really a frequently asked question:)


    "Jack Klein" <> wrote in message
    news:...
    > On Sat, 5 Jul 2003 02:23:33 -0400, "Newsgroup - Ann"
    > <> wrote in comp.lang.c:
    >
    > >
    > > From: "Newsgroup - Ann" <>
    > > Subject: char s[] = "asdf" and extern char *s in separate files
    > > Date: Saturday, July 05, 2003 2:17 AM
    > >
    > > Hi gurus,
    > >
    > > I have two files compiled together. One file has the following global
    > > definition:
    > >
    > > char s[] = "asdf";
    > >
    > > Another file has the following declaration:
    > >
    > > extern char *s;
    > >
    > > Is there anything wrong here? I know that although char* s and char s[]

    are
    > > not exactly the same, and in most case, they are interchangable.

    However,
    > > when I use them in separate files, there are problems:
    > >
    > > When I assign the value of s to another char * type local variable like
    > >
    > > char *p = s;
    > >
    > > Instead of the pointer s itself being assigned to the p, the value

    pointed
    > > by s is assgined to p. That's certainly not my intention. I know roughly

    to
    > > say, that's because the different view from the two source files, but

    how is
    > > the detail? Has anybody here ever experienced similar problems? btw, I

    am
    > > using Visual C++. Could it be a bug of VC++?
    > >
    > > News - Ann

    >
    > I guess you missed section 6 when you read the FAQ (Frequently Asked
    > Question) list for this group, before posting your frequently asked
    > question here.
    >
    > Go immediately to http://www.eskimo.com/~scs/C-faq/s6.html and read
    > the entire section, especially the first three questions:
    >
    > 6.1 I had the definition char a[6] in one source file, and in another
    > I declared extern char *a. Why didn't it work?
    >
    > 6.2 But I heard that char a[] was identical to char *a.
    >
    > 6.3 So what is meant by the ``equivalence of pointers and arrays'' in
    > C?
    >
    > The URL for the entire FAQ is in my signature.
    >
    > --
    > Jack Klein
    > Home: http://JK-Technology.Com
    > FAQs for
    > comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    > comp.lang.c++ http://www.parashift.com/c -faq-lite/
    > alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Newsgroup - Ann, Jul 5, 2003
    #1
    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. EvgueniB
    Replies:
    1
    Views:
    630
    Anthony Borla
    Dec 15, 2003
  2. Newsgroup - Ann
    Replies:
    1
    Views:
    357
    John Harrison
    Jul 5, 2003
  3. Thomas Matthews
    Replies:
    5
    Views:
    2,431
    tom_usenet
    Aug 2, 2004
  4. lovecreatesbeauty
    Replies:
    1
    Views:
    1,056
    Ian Collins
    May 9, 2006
  5. Andre
    Replies:
    5
    Views:
    541
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page