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 7790053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:28:21+00:00 2026-06-01T21:28:21+00:00

If I call a function which has a volatile parameter, and that parameter is

  • 0

If I call a function which has a volatile parameter, and that parameter is not used, must the compiler nonetheless produce the parameter?

void consume( volatile int ) { }

...

consume( some_expr );

GCC does honour this, but I’m uncertain if the wording of volatile in the standards requires this. In my opinion GCC is doing the right thing — this is logically an assignment to a volatile variable and thus should not be omitted (according to 1.9-8 of the c++ standard)

NOTE: The purpose of this is to prevent the optimizer from removing the evaluation of code. That is, it forces some_expr to be evaluated. It allows the expression to be optimized, but ensures it is actually performed.

I’ve add C and C++ as tags as the answer to both interests me should there be any differences. I don’t think there would be however.

ANSWER: I’ve picked the first one as I believe it is the correct practical realization of the standard. However, Steve’s philosophical viewpoint is very interesting and may in fact mean the standard is ambiguous.

  • 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-01T21:28:23+00:00Added an answer on June 1, 2026 at 9:28 pm

    The unnamed argument of consume cannot be read, since it’s unnamed. However, it is initialized, and that initialization (with some_expr) is a visible side-effect. Therefore the compiler may not optimize the initialization out.

    Whether this requires the actual evalution of some_expr is another matter. In general that is not a visible side-effect, but it could be if some_expr contains volatile sub-expressions.

    [edit]
    Please note that the “unnamed” part can occur in two places. The caller in general has no way to know whether a parameter is named (let alone used) E.g.

    void consume( volatile int x);
    consume( some_expr );
    // other .cpp
    void consume( volatile int ) { } // Same function.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C program which has a function call that is defined in
In which way could I call the function that automatically opens my annotation (with
I have a class and inside that class is this function which has a
I have a JavaScript file which has a function that I reference. When I
I want to call a function (which calculates my version number) when my NSIS
How to call a function which takes two parameters using threading in C#? I
I try to call a function which passed as function pointer with no argument,
In my Application I need to call a function(Which update the valuesof textviews),I need
I have a wrapper around a C++ function call which I call from C#
I want to create a simple menu function which can call it example get_menu()

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.