473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can volatile be added through declarations

Can type qualifiers be added through declarations
For example, I have one variable defined in file scope without type
qualifier. In another file, say f1.c, this variable is declared with
two qualifiers added, and in the third file f2.c, declared with only
one qualifier added.

Will the variable act just as what they are declared in each file? Is
it a const and volatile variable in f1.c and only volatile in f2.c?

/* definition.c
*************** *************** *************** *************** ***/
/*no qualifier added*/
int g_value = 0;
/* f1.c
*************** *************** *************** *************** ***********/
int f1(void)
{
/*two qualifiers added: volatile, const*/
extern int volatile const g_value;

/*...*/
return 0;
}
/* f2.c
*************** *************** *************** *************** ***********/
int f2(void)
{
/*one qualifiers added: volatile*/
extern int volatile g_value;

/*...*/
return 0;
}

Thank you for your time.
Dec 11 '07 #1
1 1209
lovecreatesbea. ..@gmail.com wrote:
Can type qualifiers be added through declarations
For example, I have one variable defined in file scope without type
qualifier. In another file, say f1.c, this variable is declared with
two qualifiers added, and in the third file f2.c, declared with only
one qualifier added.

Will the variable act just as what they are declared in each file? Is
it a const and volatile variable in f1.c and only volatile in f2.c?
The behavior is undefined.

6.7.3p9: "For two qualified types to be compatible,
both shall have the identically qualified version
of a compatible type [...]"

6.2.7p2: "All declarations that refer to the same
object or function shall have compatible type;
otherwise, the behavior is undefined."

--
Eric Sosman
es*****@ieee-dot-org.invalid
Dec 11 '07 #2

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

Similar topics

4
2498
by: Anh-Tu Vo | last post by:
Hi all, I have a weird problem on a variable assignment. It seems that the variable is only updated with the value at the second time the function is called. My program looks like this: myClass { typedef struct {
8
397
by: David Rasmussen | last post by:
What is the difference in meaning and in consequences between struct S { volatile A* a; }; and struct S
3
1940
by: Christopher M. Lusardi | last post by:
Hello, Can you tell me is it my imagination, or should I not stick a "volatile" definition into a dot h file? My problem is if I put my declaration in main.c before main () my code works. But, if I move it to a dot h and include the dot h into main.c, I get an error when I run the program. I am using the volatile qualifier because I am using mmap.
5
7903
by: ben | last post by:
Hello All, I am trying to make sense of a bit of syntax, is there a guru out there that can clear this up for me. I have a buffer declared as static volatile u8 buffer; and I have a pointer to that buffer declared as
14
11951
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that can be accessed as an atomic entity, even in the presence of asynchronous interrupts." Does this mean that the use of "volatile" in the above declaration is redundant? (It sure sounds that way to me.)
13
1906
by: yaron | last post by:
Hi all, let be focus on sigle processor machine 32 bits. 1. with multi-threaded on single processor machine 32bit do i have to sync access to atomic get/set properties of type less then 32 bits ? 2. for those properties is it enough to use volatile on single processor machine ? 3 does volatile solve the problem for multi-processor machine ? 4. does the problems optimizations/reordering/caching makes problems with multi-threading on...
6
2223
by: venky | last post by:
Hi all, I'm new to group n c. i want to know in detail about volatile qualifier and pointer to functions with examples. thank you
94
30257
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
3
2322
by: C++Liliput | last post by:
It seems that the keyword "volatile" is used to make sure that threads reading (or writing to) the same data should see a consistent picture of the variable i.e. updates made to the common data should immediately get reflected to other threads that are using it. However I have never faced this issue in y multi-threaded code even though the common variables are not declared volatile. So is this just a matter of coincidence that I have had...
0
8010
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8084
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8300
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6761
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.