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

  • Home
  • SEARCH
  • 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 4083400
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:18:29+00:00 2026-05-20T18:18:29+00:00

Is there any difference between placing the #pragma once inside the include guards as

  • 0

Is there any difference between placing the #pragma once inside the include guards as opposed to outside?

case 1:

#ifndef SOME_HEADER_H
#define SOME_HEADER_H
#pragma once

case 2:

#pragma once
#ifndef SOME_HEADER_H
#define SOME_HEADER_H

I’m just wondering out of curiosity if there’s any special cases where I should prefer one or the other (case 1 or case 2) since I’ve decided to combine both (pragma and header guards) in my code.

EDIT:

I think you guys are misinterpreting my question… I am asking about the location of pragma once, not pragma once -vs- header guards.

  • 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-05-20T18:18:30+00:00Added an answer on May 20, 2026 at 6:18 pm

    There’s a subtle difference in that if SOME_HEADER_H is already defined before the header is included, then in the second case the preprocessor will process the #pragma once, and in the first case it won’t.

    You’ll see a functional difference if you #undef SOME_HEADER_H and include the file again by the same TU:

    #define SOME_HEADER_H
    #include "some_header.h"
    #undef SOME_HEADER_H
    #include "some_header.h"
    

    Now, in case 1 I have all the definitions from the header file. In case 2 I don’t.

    Even without the #undef, you could conceivably see a difference in preprocessing time due to the #pragma once being ignored in case 1. That’s up to the implementation.

    I can think of two plausible ways it could already be defined before the first inclusion of this header file:

    • (the obvious one) a completely separate file defines it, either deliberately or by accidental name clash,
    • a copy of this file has already defined it. Depending on implementation that might include the case where this file gets involved in the same TU under two different filenames, e.g. because of a symbolic link or filesystem merge. If your implementation supports #pragma once, and you examine its documentation very carefully, you may be able to find a definitive statement whether the optimization is applied by the path under which the file is included, or by comparison of something which identifies a file’s storage, like inode number. If the latter, you may even be able to figure out whether there are still scams that could be pulled to trick the preprocessor, such as remote-mounting a local filesystem to conceal that it’s “the same file really”…

    Used in the expected way, though, there’s no difference provided that the implementation treats #pragma once in the way that Microsoft defines it. As long as it’s processed rather than skipped, it marks the containing file for the optimization, so it doesn’t matter whether or not it would be processed on a second pass through the file — the second pass won’t happen.

    And of course since the pragma is non-standard, at least in theory it could have a completely different meaning on different implementations, in which case it might matter when and how many times it is processed. In practice, you’d think nobody will do that.

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

Sidebar

Related Questions

Is there any difference between a volatile Object reference and AtomicReference in case I
Is there any difference between calling event.stopImmediatePropagation() and return false inside an event handler
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
Is there any difference between: if foo is None: pass and if foo ==
Is there any difference between website and web application project? What if you are
is there any difference between: lock((IDictionary) _collection).SyncRoot) or lock(_collection)
In VB.Net is there any difference between the following three ways of initialising object
From a desktop application developer point of view, is there any difference between developing
I'm seeing conflicting references in Oracles documentation . Is there any difference between how
if i have a standard ASP.NET application, is there any difference between making an

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.