Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:54:50+00:00 2026-06-09T11:54:50+00:00

Suppose I have the following code: my_struct_member_type *foo() { volatile my_struct *s = (my_struct

  • 0

Suppose I have the following code:

my_struct_member_type *foo() {
    volatile my_struct *s = (my_struct *)SOME_ADDRESS;
    return &(s->struct_member);
}

Is the pointer returned by foo also volatile?

EDIT: A followup: is the pointer &(s->struct_member) volatile inside of foo?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:54:51+00:00Added an answer on June 9, 2026 at 11:54 am

    Yes.

    For volatile my_struct *s says that the object you see through it is volatile and all members that you access through this pointer inherit the volatile qualification.

    Having the address of a pointer to volatile returned if the return type doesn’t say so is a constraint violation and your compiler must have given you a diagnostic for that.

    Edit: There also seems to be confusion to where the volatile keyword applies. In your example it applies to the object pointed to, not to the pointer itself. As a rule of thumb always write the qualifiers (const or volatile) as far to the right as possible without a type change. Your example then would read:

    my_struct volatile*s = (my_struct *)SOME_ADDRESS;
    

    which is entirely different from

    my_struct *volatile s = (my_struct *)SOME_ADDRESS;
    

    where the pointer itself is volatile but not the object behind it.

    Edit 2: Since you ask for my sources, the actual C standard, C11, 6.8.6.4 it says about the return statement:

    If the expression has a type different from the return type of the
    function in which it appears, the value is converted as if by
    assignment to an object having the return type of the function

    So 6.15.16.1 for the assignment operator what is expected from the conversion:

    the left operand has atomic, qualified, or unqualified pointer type,
    and (considering the type the left operand would have after lvalue
    conversion) both operands are pointers to qualified or unqualified
    versions of compatible types, and the type pointed to by the left has
    all the qualifiers of the type pointed to by the right;

    Here the pointed type on the right has the volatile qualifier in addtion to the one on the left.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have the following code: (ns foo) (defmacro defproject [project-name version & args]
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
Suppose I have the following code: void* my_alloc (size_t size) { return new char
Suppose I have the following code snippets, i.e. goo call foo, DataTable created by
Suppose we have the following class hierarchy: class ClassA: @property def foo(self): return hello
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Suppose I have the following code function myFunction(param, callback) { ... if (err) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.