what is the difference between objects and pointers?
Nov 14 '05
59 3581
Joe Wright wrote: Is a + b an object?
Another way of looking at it, is that a + b isn't an identifier.
If you don't have an identifier and you don't have an address,
then what object would you be talking about?
I only know three ways to create objects in a program.
1 Declared variables are objects.
2 String literals refer to anonymous objects,
when the string literals aren't array initializers.
3 A non NULL return value from malloc or friends, is
a pointer to an anonymous object.
--
pete
E. Robert Tisdale wrote: For the definition of the term object, you should consult an English language dictionary:
Only if you're not discussing C.
Using a Standard English dictionary to get the defintition of words,
which are technical terms, defined in the C standard, is ...
WHAT THE HELL IS WRONG WITH YOU ?!!!
--
pete
Hallvard B Furuseth wrote: Joe Wright wrote:Hallvard B Furuseth wrote: I think integer constants are objects, and that what this text refers to is lvalues like *p where p points to freed memory. That freed memory is no longer an object. From K&R2 A4 p195 "An object, sometimes called a variable, is a location in storage, and its interpretation depends on two main attributes: its 'storage class' and its 'type'."..
That doesn't sound like a constant to me. I must have missed something important earlier.
What you missed is that C is defined by the C standard, not by K&R2. The sentence you quoted illustrates why: It is wrong. It says that all objects are variables. So malloced memory, which is not a variable, is not an object.
Give me an example of an integer constant that you think is an object. Please.
1
Not the way I read it. That the constant 1 has object type (int) does
not make it an object. Its object type describes the object which might
hold the value if you wanted to store it somewhere or the
promotion/conversion rules to apply if you want to do arithmetic with
it. It is not a object.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
pete wrote: Joe Wright wrote:
Is a + b an object?
Another way of looking at it, is that a + b isn't an identifier. If you don't have an identifier and you don't have an address, then what object would you be talking about?
I only know three ways to create objects in a program. 1 Declared variables are objects. 2 String literals refer to anonymous objects, when the string literals aren't array initializers. 3 A non NULL return value from malloc or friends, is a pointer to an anonymous object.
Thanks pete. It seems you are on the side of reason (my side). There is
some wording in the standard about constants having object type. They
do. I fear this is being construed to mean that constants are objects.
They are not!
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote: pete wrote:
Joe Wright wrote:
> c = a + b;
Is a + b an object?
Yes.
No. RTBS.
Richard
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote: Joe Wright wrote:
That doesn't sound like a constant to me. I must have missed something important earlier. Give me an example of an integer constant that you think is an object.
For the definition of the term object, you should consult an English language dictionary:
http://www.bartleby.com/61/
Of course. And integers must be able to split in the middle to produce
smaller integers, and two long doubles should have sex together,
resulting in a cute little float nine nano-months later. Because, after
all, that is the dictionary meaning of "multiplication ".
Richard
Joe Wright wrote: pete wrote: Joe Wright wrote:
Is a + b an object? Another way of looking at it, is that a + b isn't an identifier. If you don't have an identifier and you don't have an address, then what object would you be talking about?
I only know three ways to create objects in a program. 1 Declared variables are objects. 2 String literals refer to anonymous objects, when the string literals aren't array initializers. 3 A non NULL return value from malloc or friends, is a pointer to an anonymous object. Thanks pete. It seems you are on the side of reason (my side). There is some wording in the standard about constants having object type. They do.
They do.
I fear this is being construed to mean that constants are objects. They are not!
They are not.
Here's that in a nutshell:
N869 6.3.2 Other operands
6.3.2.1 Lvalues and function designators
[#1] An lvalue is an expression with an object type or an
incomplete type other than void; if an lvalue does not
designate an object when it is evaluated, the behavior is
undefined.
(5) is is an expression with an object type
or an incomplete type other than void.
x = (5);
If (5) does not designate an object when it is evaluated,
the behavior is undefined.
From previous discussion on comp.std.c,
I've been informed that what they meant by
"if an lvalue does not designate an object when it is evaluated"
was, an invalidly dereferenced pointer.
char object;
char* pointer;
pointer = &object;
*(pointer + 17) = 0;
The left operand of the last above assignment,
is an example of what they meant by
"an lvalue does not designate an object when it is evaluated".
--
pete
Joe Wright wrote: pete wrote:Joe Wright wrote:
Is a + b an object? Another way of looking at it, is that a + b isn't an identifier.
What of it?
If you don't have an identifier and you don't have an address, then what object would you be talking about?
An unnamed object, of course. Or what is sometimes called a temporary
variable, depending on who you are speaking to.
There is some wording in the standard about constants having object type. They do. I fear this is being construed to mean that constants are objects.
Not by me. I've simply assuming that the text from the standard which
Pete claimed is in error in message <40***********@ mindspring.com> , is
in fact not on error. The rest follows.
It fits how I think of program execution, anyway. A (sub)expression is
evaluated. The result is a (temporary) object. That object may be
stuffed into a variable by an assignment operator, or whatever. And
the compiler may optimize away the temporary object.
Though I think I should have said that constants, when evaluated,
_become_ objects. I do agree that this does become murky one way or
another. Now that I think of it, it doesn't fit static initializers.
Then only the initialized element is an object.
--
Hallvard
pete wrote: N869 6.3.2 Other operands 6.3.2.1 Lvalues and function designators [#1] An lvalue is an expression with an object type or an incomplete type other than void; if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
(5) is is an expression with an object type or an incomplete type other than void.
x = (5);
If (5) does not designate an object when it is evaluated, the behavior is undefined.
From previous discussion on comp.std.c, I've been informed that what they meant by "if an lvalue does not designate an object when it is evaluated" was, an invalidly dereferenced pointer.
Yes, that's what I thought.
--
Hallvard
Hallvard B Furuseth wrote: Joe Wright wrote:pete wrote:Joe Wright wrote:
Is a + b an object?
Another way of looking at it, is that a + b isn't an identifier. What of it? If you don't have an identifier and you don't have an address, then what object would you be talking about? An unnamed object, of course.
That's not what an unnamed object is.
An unnamed object has an address.
All objects have either an address or an identifier or both.
a + b has neither.
Or what is sometimes called a temporary variable, depending on who you are speaking to.
Unnamed objects have specified duration and representation
described by the standard.
Temporary variables are not described by the standard
and have nothing to do with C.
For
c = a + b;
the standard doesn't say that the value of a + b will be stored
anywhere else, except in c.
--
pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yensao |
last post by:
Hi,
I have a hard time to understand difference and similarities between
Relational database model and the Object-Oriented model. Can somebody
help me with this?
Thank you in advance.
Yensao
|
by: b83503104 |
last post by:
Hi,
Can someone tell me the difference between single quote and double
quote?
Thanks
|
by: Frank |
last post by:
For my website i would like to display the age of my son in years,
months, days and hours.
For now i manage to get a result for totals. Like the total number of
days.
This is the beginning:
starttime = Date.parse("Aug 10,2003, 07:07")
sdt = new Date(starttime)
|
by: Rich |
last post by:
I was considering C# for developing a scientific application, but I have
noticed a ~30% difference between VC++ .NET and C# on the same machine,
under identical conditions:
double a = 0,b = 0, c = 0, d = 0, e = 0;
for(int n = 0; n != 6000000; n++)
{
a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2;
c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
|
by: jamesyreid |
last post by:
Hi,
I'm really sorry to post this as I know it must have been asked
countless times before, but I can't find an answer anywhere.
Does anyone have a snippet of JavaScript code I could borrow which
calculated the difference in years and days between two dates, and
takes leap years into account?
I'm calculating the difference in the usual way, i.e....
| |
by: bbawa1 |
last post by:
Hi,
I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.
In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.
|
by: Petronius |
last post by:
Hallo, does anyone have an idea how to implement difference lists in
Javascript?
Thanks allot in advance
|
by: Julius |
last post by:
Hej dudes,
I need to calc the difference between two timestamps / dates ...
For example what i need to calculate:
Date 1: 2007.11.06 - 20:13:04
Date 2: 2007.11.07 - 21:13:04
Difference: 1 day, 1hour
|
by: viki1967 |
last post by:
Hi all!
This new forum its great! :)
Congratulations !!!
My answer: why this my code not working?
Nothing error but not work the difference.... :
<html>
|
by: cmb3587 |
last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays
Ex:
arrayA: 3 5 8 9
arrayB: 3 4 6 9
difference of A-B: 5 8
however, my code is just returning me an array of 0's
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |