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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:44:31+00:00 2026-05-20T20:44:31+00:00

I came across this code snippet 1 int return_printChar1() { // code // oops!

  • 0

I came across this code snippet 1

int return_printChar1()
{
    // code
    // oops! no return statement
}
int return_printChar2()
{
    // code
    return printf("Return");
}
int main()
{  
   int i;
   // some more code
   i = return_printChar2();
   if((return_printChar1(),i))
   {
      printf ("Gotcha");
   }
}

1: This is not a real life example.

My question is “Is the behaviour of the code snippet well defined in C and C++?“

My take:

In C the behaviour is well defined because 6.5.17 says

The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation

In C++03 the behaviour is well defined because 5.18 says

A pair of expressions separated by a comma is evaluated left-to-right and the value of the left expression is discarded.

However C++03 (in section 6.6.3) also says that

Flowing off the end of a function is equivalent to a returnwith no value; this results in undefined behavior in a value-returning function.

Similarly in C

If control reaches end (}) of non-void function (except main()) the behaviour is undefined.

So taking all these points into consideration I can’t judge the actual behaviour. What do you people think?

P.S: If you think the question is useless and you have got better things to do, help yourself: D.

  • 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-20T20:44:32+00:00Added an answer on May 20, 2026 at 8:44 pm

    The C spec I have (C99 TC3) says

    If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.

    The value of an expression that’s said to be “evaluated as a void expression” is discarded. So in the C case, there is no undefined behavior. It may have been different in old C (some details are, if I remember correctly).

    The situation for C++ is slightly different than for C, because C++ supports class objects with constructor and destructors as return values and having them operate on uninitialized memory can’t be guaranteed to work well. Perhaps this contributed to the different rules for C++.

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

Sidebar

Related Questions

I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;
I came across a code snippet like this: Timestamp expiryDate = Timestamp.valueOf(dateStr + +
I recently came across this in some code - basically someone trying to create
I came across this line in some code and can't find the syntax defined
Yesterday I read some code of a colleague and came across this: class a_class
I came across this strange code snippet which compiles fine: class Car { public:
Context I came across some code, like this: if( Some_Condition ) throw 0; I
In the Pragmatic Core Data book, I came across this code snippet for an
I came across something peculiar today. Take a look at this code snippet: List
I came across this code today AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); Is there anything wrong with

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.