473,382 Members | 1,376 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,382 software developers and data experts.

'static' to make object accessible by file

Lax

Say we have a static external object (object defined outside of any
block with static qualifier) in a file.
We are telling the compiler that we intend that object to be accessed
by functions in the current file that are below the definition.

Now what if one of these functions passes a pointer value to this
object to a function in another file, and that function uses the
pointer to access this static object? Is this 'normal' or dependent on
the specific environment?

This works on my system but I am not sure if this is a normal thing I
should be doing or it's just because my environment/compiler isn't
picking up on the bad move. If it's okay, is it bad style?

So, does the C standard say that such a move is allowed (either
directly or indirectly by not saying that it is disallowed)?

Jun 27 '08 #1
2 1005
Lax wrote:
Say we have a static external object (object defined outside of any
block with static qualifier) in a file.
We are telling the compiler that we intend that object to be accessed
by functions in the current file that are below the definition.

Now what if one of these functions passes a pointer value to this
object to a function in another file, and that function uses the
pointer to access this static object? Is this 'normal' or dependent on
the specific environment?
Normal. A static object does not have global linkage, but it still has
to exist somewhere.

--
Ian Collins.
Jun 27 '08 #2
In article <78**********************************@e39g2000hsf. googlegroups.com>,
Lax <La********@gmail.comwrote:
>Say we have a static external object (object defined outside of any
block with static qualifier) in a file.
We are telling the compiler that we intend that object to be accessed
by functions in the current file that are below the definition.
>Now what if one of these functions passes a pointer value to this
object to a function in another file, and that function uses the
pointer to access this static object? Is this 'normal' or dependent on
the specific environment?
That is normal and allowed. There are lurking dangers, such as if
the static data is declared const but the routines do not consistantly
use the const qualifier and ending up modifying the data.
--
'Roberson' is my family name; my given name is 'Walter'.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
4
by: J.J.García | last post by:
Hi, I have defined an static operator in a class, and when I try to use it inside of the class, my compiler --Visual C++ 7.1-- complains saying that there not exist an operator that suits the...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: Martin Eyles | last post by:
Hi, I have an xml config file for my website, which stores all the information required to connect to a database. I have used the following code to get the xml file into my program as an object,...
5
by: kselvaakumar | last post by:
I have declared a global structure like this: struct { float a; float b; }static one; This is in a separate header file file1.h; Now how can i initialise those variables one.a and one.b in...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
2
by: hayyal | last post by:
Hi Folks, Just wanted to know few things about static variables. why static variables cannot be accessed in other files by using extern in c/c++? whats the difference between global and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.