473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
1 3842

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: asdf | last post by:
Hello, I was enjoying working in VS for half a year without any problems and now I cannot debug anymore. Without any really reason my Studio tells me that the page that I want to debug has - No...
11
by: taoberly | last post by:
A few months ago I posted a question about using a file on my hard drive to perform cross-frame scripting and pull data from a server on my company's intranet. I eventually got this working using...
3
by: rosedream | last post by:
I'm using BlueJ, not really sure if there is a diffrence in versions... i'm using windows XP if more info would be needed to indentify specific solution, please tell me what is needed. If this is a...
1
Carrugar
by: Carrugar | last post by:
Hi folks, I am issuing the net use command on a couple of Win2003 servers. Some of these servers require that the name and password be authenticated twice and other servers just once, i.e.: ...
8
by: anon.asdf | last post by:
Hi! OK, lets try "array-copy": { char arrayA; arrayA = (char){1, 2, 3}; } it does *not* work since we're trying to make a fixed array-pointer arrayA, point to another location/address...
2
by: dhtmlkitchen | last post by:
I'm trying to learn something about JScript engine. I have the following example: <script>(function() { poop = "brown"; myFunction = function myFunction() {}
9
by: anon.asdf | last post by:
In terms of efficieny: Is it better to use multiple putchar()'s after one another as one gets to new char's OR is it better to collect the characters to a char-array first, and then use...
7
by: jodleren | last post by:
Hi I have used JS for years, still I dont know this. I know the difference in php but not in js. window.open('page.htm'); and window.open("page.htm"); - what is the difference? /S
2
by: anon.asdf | last post by:
Hello! 1) =============================== When trying to define an array of std::string ... func( (std::string ) { std::string("ab"), std::string("cd"), std::string("ef") } , 3 ); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.