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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:40:40+00:00 2026-06-14T02:40:40+00:00

How I can say to the compiler how to optimize something or what some

  • 0

How I can say to the compiler how to optimize something or what some call to function.
I mean like create allocate method and let the compiler optimize it as it optimize it with malloc or new.

Or like if somewhere in the code the function X is called and it’s return value is not used then delete this call. (Function from .lib that the compiler don’t know a piece about it)

There are options for this?

For example:

auto val=X(); //Use the return value
X(); //Don't use
auto t=allocate<T>(); //Allocate on heap
t->Show(val); //Run single function and don't use it's pointer somewhere (Save it after the function is exit)

And optimize it to:

X(); //First line, just call it
T().Show(val); //Combines third and fourth lines, Allocate on stack and run the single function

If you asking ‘why you need this?’ I am creating programming language with my own GC and heap. (And lot of things too)

It translates to C++ then I don’t want to optimize the code while translate it. (It’s gonna be a pain)
Because I can call functions randomly in places. (I can’t detect if their values are used or not)

  • 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-14T02:40:41+00:00Added an answer on June 14, 2026 at 2:40 am

    Optimization is compiler-specific, so you’ll need to look in your compiler’s documentation to see what optimization “hints” it allows you to put in code. For example, here are some of GCC’s function attributes:

    • The malloc attribute tells the compiler that if the function returns a non-null pointer, it’s always a “new” area of memory, not another pointer to something that’s already been allocated. You’d probably want to use this on a function that wraps the real malloc().
    • The const attribute (different from the ordinary const keyword) says that the function’s return value depends solely on its arguments and has no side effects, so it’s safe for the compiler to eliminate duplicate calls with the same arguments.
    • The noreturn attribute tells the compiler that a function never returns; you’d use this on functions that terminate the program, like C’s exit().

    Attributes go on the declaration of a function, typically in a header file, so you can use them even if the function’s implementation is in a compiled library that’ll be linked in later. But remember that function attributes are promises from you to the compiler: if you declare a function with the noreturn attribute, for example, and then implement it with code that actually can return, strange things may happen at runtime when it does.


    You can also use function attributes to help with correctness checking:

    • The nonnull attribute tells the compiler that certain (pointer) arguments aren’t supposed to be null, so it can issue warnings if it detects that they might be.
    • The format argument tells the compiler that the function takes a format string like C’s printf(), so it can check that the types of the variadic arguments match the corresponding format codes in the format string. (For example, you shouldn’t write “%s” in the format string but then pass an integer as its value.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I would like to have DataTemplates such that I can say:
Can we say passing a function pointer as an argument to a function is
Let's say we have a class that looks like this: class A { public:
Say I have a C++ function debugPrint(int foo). How can I most conveniently strip
How can I tell closure compiler that an anonymous function should not be removed
The release notes for GWT 2.5 say that the GWT compiler can optionally use
Let's say the bottleneck of my Java program really is some tight loops to
All, Lets say I have an assembly compiled under .NET 2.0. Can I run
One can say a type parameter T must have a specific supertype S_1: class
In SQL server I can say: Select top 50 percent How can I say

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.