467,097 Members | 1,198 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,097 developers. It's quick & easy.

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

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
Jul 19 '05 #1
  • viewed: 3612
Share:
1 Reply

"Newsgroup - Ann" <ne******@yahoo.com> wrote in message
news:3f**********@rcfnews.cs.umass.edu...
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:
Not exactly the same means different. The first is an array, the second is a
pointer. Do this

extern char s[]; // s is an array

When I assign the value of s to another char * type local variable like

char *p = s;

Instead of the pointer s itself
s is not a pointer.
being assigned to the p, the value pointed
by s is assgined to p.
That doesn't make sense. The value 'pointed' to by s is a char, how can a
char be assigned to a pointer?
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?
There is no detail, your code is wrong so you get incorrect behaviour.
Has anybody here ever experienced similar problems? btw, I am
using Visual C++. Could it be a bug of VC++?
No, your code is wrong. Fix the code like I explained and if you are still
having problems post the corrected code.

News - Ann


john
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by taoberly@mindspring.com | last post: by
3 posts views Thread by rosedream | last post: by
8 posts views Thread by anon.asdf@gmail.com | last post: by
2 posts views Thread by dhtmlkitchen@gmail.com | last post: by
7 posts views Thread by jodleren | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.