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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:46:09+00:00 2026-06-15T08:46:09+00:00

__attribute__((const)) is a GCC attribution to check purity of the function execution. I think

  • 0

__attribute__((const)) is a GCC attribution to check purity of the function execution.
I think this is being supported on Clang, but when I put this to a method, it doesn’t seem to work.

@interface C1
- (id)method1 __attribute__((const));
@end


int a = 0;

@implementation C1
- (id)method1 __attribute__((const))
{
    a++;
    return nil;
}
@end

The code above doesn’t generate any warning or error.

Is this attribution working on Clang? Or what should I do to make this to work?

  • 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-15T08:46:10+00:00Added an answer on June 15, 2026 at 8:46 am

    The const attribute doesn’t check the purity of the function. It declares the purity of the function, so the optimizer can eliminate calls to the function. It’s up to you to actually make sure the function is pure.

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

Sidebar

Related Questions

In C++ you may declare function with exception specification like this: int foo() const
gcc does not like the following code: inline const plus(unsigned x,unsigned y) __attribute__((pure)); inline
With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this
Currently I use this function, based on JCL code, which works fine: function IsDirectoryWriteable(const
How (in GCC/GNU C) do you declare a function pointer which points to an
What does this GCC warning mean? cpfs.c:232:33: warning: ISO C99 requires rest arguments to
How can I declare the Color type as const like this: private const Color
following this link I did: static const struct attribute const *attrs1= { &foo_attribute.attr, NULL,
I have the following function but my compiler (VS2003) says that the assignement T
From this article . Another use for declaring a variable as register and const

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.