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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:01:01+00:00 2026-06-12T07:01:01+00:00

I tried to call a self-written function without handling its return value. gcc told

  • 0

I tried to call a self-written function without handling its return value. gcc told me at the line of the function call that this would be a statement with no effect.
To check whether my function gets called at all, I added some printf statement, but didn’t get any output from the program.

Is it possible that gcc simply ignores the function call? As far as I know, I never had any problems with such statements.

So here is the code:

unsigned strlen(char *string)
{
  printf("ignored by gcc");
  unsigned count = 0;
  for(; *string++; count++);
  return count;
}

int main()
{
  char string[] = "something";
  strlen(string);

  return 0;
}

Thanks in advance.

  • 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-12T07:01:02+00:00Added an answer on June 12, 2026 at 7:01 am

    It is perfectly legal to ignore the return value of a function. You probably do it more than 99% of the times you invoke printf() (which returns an int).

    However, as several persons have said in the comments, you called your function strlen() after a standard library function. This is illegal according to C99’s 7.1.3:2:

    If the program declares or defines an identifier in a context in which
    it is reserved (other than as allowed by 7.1.4), or defines a reserved
    identifier as a macro name, the behavior is undefined.

    Here the compiler warns unexpectedly, and either calls the standard function instead of yours, or calls no function at all (since it knows its strlen() is supposed to be without side-effects). This is one of the things undefined behavior can do.

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

Sidebar

Related Questions

I want to ask,i tried to call webapp.RequestHandler ,but this handler didn't called: this
I am trying to call c# function from javascript the code i have tried
I would like to call JavaScript function many time . I have tried like
I've dug the manual and tried extensivelly to drop the extra function(){...} call after
So, I have a class like this: class Test(object): def call(self,instruction,data): pass def handle_foo(self,data):
When I call self.class.instance_variable_set(@var, ...) from inside a class method, where is that variable
I tried to call a .NET web service with KSOAP2 and it throws an
When I tried to call a class called ShowHistory in Java, an error shows:
I am trying datatables. I successfully tried on ajax call. But now I am
How to create a generic method which can call overloaded methods? I tried but

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.