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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:27:38+00:00 2026-06-06T20:27:38+00:00

I have a bit of sample code that is throwing this warning: main.c: In

  • 0

I have a bit of sample code that is throwing this warning:

main.c: In function ‘getline_’:
main.c:30:32: warning: operation on ‘c’ may be undefined [-Wsequence-point]

In this particular exercise I was to avoid using the || and && operator, but this doesn’t seem like it should produce undefined behavior. The compiler message is just a warning, but I wanted to know for knowings sake. Is this code actually going to produce undefined behavior?

 24 int getline_( char s[], int limit)
 25 {
 26     int i, c;
 27     i=0;
 28     for( i=0; (i<limit-1) + ((c=getchar())!='\n') + (c!=EOF) == 3; i++){
 29            s[i]=c;
 30     }
 31     if( c == '\n' ){
 32         s[i]=c;
 33         i++;
 34     }
 35     s[i]='\0';
 36     return i;
 37 }

It seems to work ok in my basic tests.

Edit: Updated title as per comment, thanks pst.

  • 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-06T20:27:40+00:00Added an answer on June 6, 2026 at 8:27 pm

    This is unspecified behavior:

    (i<limit-1) + ((c=getchar())!='\n') + (c!=EOF) == 3

    the order of evaluation of expressions between sequence points is unspecified in C. It is unspecified if the assignment to c occurs before the equality check with EOF.

    In addition to the unspecified behavior, it is also undefined behavior because it violates the sequence points rules and particularly this one:

    (C99, 6.5p2) “Furthermore, the prior value shall be read only to determine the value to be stored.”

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

Sidebar

Related Questions

I have this little bit of code that I can't quite work correctly. The
I have a very simple bit of code that is supposed to capture the
I have a bit of JavaScript code that is specified in a configuration file
I have a bit of Java code that outputs an XML file to a
I have a small bit of code that I'm trying to execute with the
I have a bit of xml file named Sample.xml which is shown below <?xml
I have a pretty simple ASP.NET Web Form that looks a bit like the
I am using ubuntu 12.04 on 64 bit machine, I have this simple C
Below is a very simple bit of code that mimics a class structure in
The following site Writing Boot Sector Code provides a sample of code that prints

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.