473,657 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are these behaviors defined?

I'm working on some lessons and want to be sure I get some stuff correct. If
any of this is covered in the FAQ, please feel free to point me to the
section - I couldn't find it.

----------------------------------------------------------------
Overflow/Wraparound behavior of integer values
----------------------------------------------------------------

If an arithmetic operation such as (+, -, *) yields a result that exceeds
the bounds, is the behavior in any way defined? I know that, for instance,
integers will generally wrap around - but is this the defined behavior?

----------------------------------------------------------------
Logical Operators on floating point values
----------------------------------------------------------------

I know that the bitwise operators are not defined for floating point
representations (though I have no idea why unless it might be to avoid
imposing behavior that might be more difficult to implement if the values
involved are in a floating point unit - any thoughts?). My question is the
logical operators (!, &&, and ||). Are the behaviors of these defined at
all?

----------------------------------------------------------------
Standard I/O Functions when given NULL stream pointers
----------------------------------------------------------------

Are the behaviors of functions like free(), fprintf(), fclose(), getc() and
others defined if they are passed a NULL stream pointer?

----------------------------------------------------------------
Value of bits shifted in by >> and <<
----------------------------------------------------------------

Are the values that are shifted into the msb's of an integer when it is
shifted to the left (and the lsb's when shifted to the right) defined in any
way?

----------------------------------------------------------------
Are float and double representations fixed?
----------------------------------------------------------------

By this, I mean is a float guaranteed to be a four-byte IEEE-754 single
precision representation and a double an eight-byte double precision
representation, or are these only minimum requirements.


Nov 14 '05 #1
7 1659
William L. Bahn <wi*****@toomuc hspam.net> scribbled the following:
I'm working on some lessons and want to be sure I get some stuff correct. If
any of this is covered in the FAQ, please feel free to point me to the
section - I couldn't find it. ----------------------------------------------------------------
Overflow/Wraparound behavior of integer values
---------------------------------------------------------------- If an arithmetic operation such as (+, -, *) yields a result that exceeds
the bounds, is the behavior in any way defined? I know that, for instance,
integers will generally wrap around - but is this the defined behavior?
Unsigned integer types will wrap around, this is defined behaviour. The
behaviour for signed integer types is implementation-defined IIRC.
----------------------------------------------------------------
Standard I/O Functions when given NULL stream pointers
---------------------------------------------------------------- Are the behaviors of functions like free(), fprintf(), fclose(), getc() and
others defined if they are passed a NULL stream pointer?
free(NULL) is a safe no-op (however passing a stream pointer to free
causes undefined behaviour). fflush(NULL) flushes all currently open
output streams. I don't think it is defined for any other function.
----------------------------------------------------------------
Are float and double representations fixed?
---------------------------------------------------------------- By this, I mean is a float guaranteed to be a four-byte IEEE-754 single
precision representation and a double an eight-byte double precision
representation, or are these only minimum requirements.


I don't think it's required to be IEEE-754 at all, but I could be
mistaken.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To err is human. To really louse things up takes a computer."
- Anon
Nov 14 '05 #2
"William L. Bahn" wrote:

I'm working on some lessons and want to be sure I get some stuff
correct. If any of this is covered in the FAQ, please feel free
to point me to the section - I couldn't find it.

----------------------------------------------------------------
Overflow/Wraparound behavior of integer values
----------------------------------------------------------------

If an arithmetic operation such as (+, -, *) yields a result that
exceeds the bounds, is the behavior in any way defined? I know
that, for instance, integers will generally wrap around - but is
this the defined behavior?
no, the behavior is specifically undefined. Don't do that.

Also, please try to keep your line length well below 80, so that
quotes do not wrap. 65 is a good value to aim for. I have
reformatted the quotes here.

----------------------------------------------------------------
Logical Operators on floating point values
----------------------------------------------------------------

I know that the bitwise operators are not defined for floating
point representations (though I have no idea why unless it might
be to avoid imposing behavior that might be more difficult to
implement if the values involved are in a floating point unit
- any thoughts?). My question is the logical operators (!, &&,
and ||). Are the behaviors of these defined at all?
No. Because the bit format of floats is not specified.

----------------------------------------------------------------
Standard I/O Functions when given NULL stream pointers
----------------------------------------------------------------

Are the behaviors of functions like free(), fprintf(), fclose(),
getc() and others defined if they are passed a NULL stream
pointer?
free() doesn't receive a stream pointer, and free(NULL) is
allowable and a no op. The others mentioned, no. In general,
read the functions specification in the standard. A free version
is N869 (google for it). Get the text version, which is easily
searched with grep or an editor to find those definitions.

----------------------------------------------------------------
Value of bits shifted in by >> and <<
----------------------------------------------------------------

Are the values that are shifted into the msb's of an integer when
it is shifted to the left (and the lsb's when shifted to the
right) defined in any way?
for left shift, 0. For right shift, implementation defined.

----------------------------------------------------------------
Are float and double representations fixed?
----------------------------------------------------------------

By this, I mean is a float guaranteed to be a four-byte IEEE-754
single precision representation and a double an eight-byte double
precision representation, or are these only minimum requirements.


Absolutely not. See the standard.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #3
On Sat, 7 Aug 2004 05:16:04 -0600, "William L. Bahn"
<wi*****@toomuc hspam.net> wrote in comp.lang.c:
I'm working on some lessons and want to be sure I get some stuff correct. If
any of this is covered in the FAQ, please feel free to point me to the
section - I couldn't find it.

----------------------------------------------------------------
Overflow/Wraparound behavior of integer values
----------------------------------------------------------------

If an arithmetic operation such as (+, -, *) yields a result that exceeds
the bounds, is the behavior in any way defined? I know that, for instance,
integers will generally wrap around - but is this the defined behavior?
The unsigned integer types cannot overflow. If a calculation produces
an out-of-range result, it is adjusted by adding or subtracting
(maximum value of the unsigned type + 1) until the result is within
range. This is often called 'modulo arithmetic'.

Overflow of signed integer types produces undefined behavior. Nothing
at all is guaranteed.
----------------------------------------------------------------
Logical Operators on floating point values
----------------------------------------------------------------

I know that the bitwise operators are not defined for floating point
representations (though I have no idea why unless it might be to avoid
imposing behavior that might be more difficult to implement if the values
involved are in a floating point unit - any thoughts?). My question is the
logical operators (!, &&, and ||). Are the behaviors of these defined at
all?
The logical operators are defined for all legal expressions, other
than those of type void.

if(float_var) yields the value 0 if float_var is exactly 0.0 and 1
otherwise.
----------------------------------------------------------------
Standard I/O Functions when given NULL stream pointers
----------------------------------------------------------------

Are the behaviors of functions like free(), fprintf(), fclose(), getc() and
others defined if they are passed a NULL stream pointer?
As others have said, free() is not a FILE * function. The others you
have mentioned produce undefined behavior if passed a null pointer.
In general, the C standard states that all functions receiving pointer
arguments have undefined behavior if passed an invalid or null
pointer, unless specifically documented otherwise.
----------------------------------------------------------------
Value of bits shifted in by >> and <<
----------------------------------------------------------------

Are the values that are shifted into the msb's of an integer when it is
shifted to the left (and the lsb's when shifted to the right) defined in any
way?
For left shifts and right shifts of unsigned integer types and signed
integer types with positive values, zero bits are shifted in. For
right shifts of signed integer types with negative values, it is
implementation-defined whether one or zero bits are shifted in. The
compiler must document which behavior it uses.

----------------------------------------------------------------
Are float and double representations fixed?
----------------------------------------------------------------


No, they are completely unspecified by the language. It is entirely
up to the compiler and the underlying hardware platform. IEEE
representation is common on newer platforms, but not required in any
way.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
Thanks to all who have responded. To summarize (please correct any errors):
----------------------------------------------------------------
Overflow/Wraparound behavior of integer values
----------------------------------------------------------------

Defined for integer types with modulo (or 'wraparound') behavior.
Undefined for signed types.

----------------------------------------------------------------
Logical Operators on floating point values
----------------------------------------------------------------

Got mixed feedback on this one. One said no, because the bit
pattern is not defined. One said yes, following the same rules as
other expressions. Since a NULL pointer is regarded as false in
an expression regardless of its interal representation, either answer
seems reasonable to me.

I've downloaded N869 and, by ommision more than anything,
it appears to support the second claim - that a floating point
value would evaluate as true just as in the expression (!(0 = = x)).

Similarly, it looks like the bitwise operators are not undefined for
floating point values - again, by ommision as it doesn't say that
they aren't defined.

But are promotions done on bitwise operands? In other words,
if I were to create a bitmask designed to maskoff all but the exponent
of a floating point value (based on knowledge of the implementation
of a float, of course) and did a bitwise & between it and the float
in question, would it promote my mask to a floating point representation?

I can't determine the answer to any of this based on searching N869
so would really appreciate someone pointing out the sections that
spell it out.

----------------------------------------------------------------
Standard I/O Functions when given NULL stream pointers
----------------------------------------------------------------

Not defined except for specific functions.

----------------------------------------------------------------
Are float and double representations fixed?
----------------------------------------------------------------

No. Any they are not required to be IEEE-754 at all.

This answers another question that I had with regards to why the
FAQ says that setting a block of memory to all zeros is not a safe
operation if the data in the block is supposed to be either pointers
or floating point values. The pointers part I understood, but I didn't
understand the floating point part since all zeros is zero in an
IEEE 754 representation.



Nov 14 '05 #5
In article <10************ *@corp.supernew s.com>,
"William L. Bahn" <wi*****@toomuc hspam.net> wrote:
Similarly, it looks like the bitwise operators are not undefined for
floating point values - again, by ommision as it doesn't say that
they aren't defined.


May I quote: "Some operators (... collectively called the bitwise
operators) are required to have operands that have integer types.

Anyway, anything that is ommited is undefined. If it is not defined,
then it is undefined.
Nov 14 '05 #6

"Christian Bau" <ch***********@ cbau.freeserve. co.uk> wrote in message
news:ch******** *************** **********@slb-newsm1.svr.pol. co.uk...
In article <10************ *@corp.supernew s.com>,
"William L. Bahn" <wi*****@toomuc hspam.net> wrote:
Similarly, it looks like the bitwise operators are not undefined for
floating point values - again, by ommision as it doesn't say that
they aren't defined.
May I quote: "Some operators (... collectively called the bitwise
operators) are required to have operands that have integer types.


Okay - I found that. Thank you.

I also see now where each of the operators states a constraint that it
must be of integer type. Don't know how I missed that before.

Anyway, anything that is ommited is undefined. If it is not defined,
then it is undefined.


That's a nice platitude, but it is frequently not very helpful when delving
through a several hundred page document where so much is defined
indirectly through several layers of arcane syntax.


Nov 14 '05 #7
William L. Bahn wrote:
----------------------------------------------------------------
Logical Operators on floating point values
----------------------------------------------------------------

Got mixed feedback on this one. One said no, because the bit
pattern is not defined.


His reason suggests that he thought that he was replying to
"Bitwise Operators on floating point values"

(!x) is semantically identical to (x == 0).
If x is a floating type, then those expressions
are also equivalent to (x == 0.0),
and (x || 0) is equivalent to (x != 0.0)
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1628
by: Catherine Lynn Wood | last post by:
I have a page that I just developed using a combination of stylesheets and div layers. It uses a 'tab' style system placing four div layers in the same space with visibility 'hidden' and position absolute. They are inside of another parent div container with position set relative so that as I make the objects visible, I can also set their position to relative so they redraw the container size. The parent div is inside of a table cell...
1
4260
by: Harlan Messinger | last post by:
I went to the W3C site to see if behaviors were discussed--something like CSS but for event handlers (onclick, etc.) rather than attributes. They are, at http://www.w3.org/TR/1999/WD-becss-19990804 Are any current browsers implementing this? I know IE has something called "behaviors" but I don't know if it's the same thing, or in accordance with this standard.
0
1527
by: Luigi | last post by:
I would know what "criteria" is used in box positioning with the position property. Here my tries (using IE and Opera): I have a box with an absolute positioning (properties used: position, left and top). I noted that if the reference of this box is the "html" box or the "body" box, the browser uses the following rules:
7
2709
by: sonic | last post by:
Hello, I am cloning a table row which contains images that have behaviors attached to them as well as onclick events. The problem is that the cloned row seems to be executing the behavior/events on the original rows image. I overwrote the onclick as well as attached a behavior to the image in cloned row, but events such as onmouseover execute now on both images when the duplicate is mouse overed.
1
1338
by: Scupper | last post by:
I have been experimenting with adding some of the IE filters to an ASPX page, and have encountered a problem. Strangely, though the page will render in VS's browse window, it will not load in IE when pulling from the localhost using exactly the same URL. Here is the header of the ASPX file so you know what includes I'm using. <%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="DefaultPage" %>...
4
1444
by: David Tilman | last post by:
I've created a web application using ASP .NET that creates tables similar to Gantt charts. There are 5 tables will 180 cells each, so there are about 900 cells on the web page. I had javascript in the attributes of each cell to react to various events (onmouseout, onmouseover, onmouseup, onmousedown) to handle highlighting and selecting cells in the chart. I wanted to try to make the application more efficient and have a smaller HTML...
1
1433
by: Mark Denardo | last post by:
I recently upgraded to VS2005 and converted some projects from 1.1 to 2.0 and am seeing two weird behaviors I can't seem to resolve, and am wondering if they are bugs or something I'm forgetting to do or add. (issue 1) When setting up a panel control with border settings: <asp:Panel Backcolor="BurlyWood" Borderstyle="Ridge" BorderColor="Black" BorderWidth="1px" ... Runat="server" />
2
1521
by: Matt Nordhoff | last post by:
Sebastjan Trepca wrote: Python doesn't like when you read a variable that exists in an outer scope, then try to assign to it in this scope. (When you do "a = b", "b" is processed first. In this case, Python doesn't find a "value" variable in this scope, so it checks the outer scope, and does find it. But then when it gets to the "a = " part... well, I don't know, but it doesn't like it.)
8
1910
by: Bo Yang | last post by:
Hi, Today, I make some test on the C++ STL iterators of set containers with GNU g++ compiler. The code is: #include <set> #include <iostream> using namespace std; int main(int argc, char **argv)
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.