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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:57:31+00:00 2026-06-04T06:57:31+00:00

I have a Visual C++ program that opens a file in one thread with

  • 0

I have a Visual C++ program that opens a file in one thread with FILE* fp = fopen(...). I want that thread to block on an event object while another thread reads the file, then signals the blocked thread when it is done, which will then close the file. Because fp is shared between threads, I have declared it as volatile FILE* fp. However, fread() won’t accept a volatile as its FILE* argument. I tried using a local pointer, with FILE* fpLocal = fp; in the thread that will call fread(), but that got me this:

 Error: a value of type "volatile FILE*" cannot be assigned to an entity of type "FILE*"

Naturally, this has me worried that maybe I’m making a mistake by trying to open a file in one thread and read it in another to begin with, though I don’t see why (yet).

Can someone help me with this? Why can’t I assign a volatile FILE* to a FILE*?

  • 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-04T06:57:32+00:00Added an answer on June 4, 2026 at 6:57 am

    Why can’t I assign a volatile FILE* to a FILE*?

    Because C++ has strict type checking and you cannot assign types that do not match to each other.
    One needs to use casting operators if that be the case, however it is important to note that using them incorrectly might lead to Undefined Behaviors as well.
    This behavior is same as for the const qualifier.

    As a side note as already mentioned in comments, volatile is not the way to go here.

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

Sidebar

Related Questions

I have a program that compares two files. I ran visual studio analysis and
I have a mixed mode C++-CLI program in Visual Studio 2005 that is set
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I have a program that works when, a file is opened with it using
I have visual studio 2008. I have a written a small C program. I
I have compilled program in Visual Studio 2011 on Windows consumer preview with v110
I have a very large program which I have been compiling under visual studio
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I'm using Visual Studio 2008. I have a DLL and a test program EXE.
I want to be able to read from an unsorted source text file (one

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.