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

Home Posts Topics Members FAQ

function is not an object

True or false ?

Sep 16 '06 #1
20 2044
asdf wrote:
True or false ?
Objects have state, identity, lifespan, storage, and behavior. Which of
those do functions have? Can you point to a function?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 16 '06 #2
So function is not an object.

But I think I can point to a function, by the pointer to the function.

Phlip wrote:
asdf wrote:
True or false ?

Objects have state, identity, lifespan, storage, and behavior. Which of
those do functions have? Can you point to a function?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 16 '06 #3

asdf wrote:
True or false ?
This question seems to be about how the c++ community defines the
"object" concept.

I would say "false". Here's why.

The * symbol is used for dereferencing or defining a pointer to an
object.

However, the * symbol is also used to define a pointer to a function.

So, if a function is not an object, what is the type-of-thing that a
pointer to a function points to?

I would say that a pointer-to-a-function is an example of a
pointer-to-an-object, and hence a function is an object.

Paul Epstein

Sep 16 '06 #4
asdf wrote:
True or false ?
From the standard [1.8/1]

The constructs in a C++ program create, destroy, refer to, access, and
manipulate objects. An object is a region of storage. [Note: A function is
not an object, regardless of whether or not it occupies storage in the way
that objects do.]
Best

Kai-Uwe Bux
Sep 16 '06 #5
"asdf" <li*********@gm ail.comwrote:
True or false ?
From the book C++ FAQs 2nd ed.

FAQ 5.06: What is an object? It depends on who you are. To a
programmer, an object is a region of storage with associated
semantics. To a designer, an object is any identifiable component in
the problem domain.

FAQ 5.08: A class can be thought of as a C=style function that can
maintain state between invocations in a thread-safe manner and can
also provide multiple services. If there wer exactly one instance of
a class, and all its member functions except for exactly one public:
member function were removed, the result would be a C-style function
(the object's data would correspond to static data that is local to
the function.)

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 16 '06 #6
>Objects have state, identity, lifespan, storage, and behavior. Which of
>those do functions have? Can you point to a function?
asdf top-posted:
So function is not an object.
Read what I wrote. I think functions have all of those. Except you can't
create them with 'new', so their lifetime options are kind'a limit.

Daniel T. wrote:
From the book C++ FAQs 2nd ed.

FAQ 5.06: What is an object? It depends on who you are. To a
programmer, an object is a region of storage with associated
semantics. To a designer, an object is any identifiable component in
the problem domain.

FAQ 5.08: A class can be thought of as a C=style function that can
maintain state between invocations in a thread-safe manner and can
also provide multiple services. If there wer exactly one instance of
a class, and all its member functions except for exactly one public:
member function were removed, the result would be a C-style function
(the object's data would correspond to static data that is local to
the function.)
However, the book Design Patterns sez to create the Flyweight Design
Pattern, you create a table of objects, each with no state.

Now if I felt like implementing that pattern using a table of function
pointers, then do I don't have a "reeeeeal" Flyweight Design Pattern??

Or is the Standard's answer to the question "are functions objects?" not
always absolute and perfectly useful?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 16 '06 #7
"Phlip" <ph******@yahoo .comwrote:
>>Objects have state, identity, lifespan, storage, and behavior.
Which of those do functions have? Can you point to a function?

asdf top-posted:
>So function is not an object.

Read what I wrote. I think functions have all of those. Except you
can't create them with 'new', so their lifetime options are kind'a
limit.
How does a function have state? More spicifically how does it have more
than one state?
Daniel T. wrote:
>From the book C++ FAQs 2nd ed.

FAQ 5.06: What is an object? It depends on who you are. To a
programmer, an object is a region of storage with associated
semantics. To a designer, an object is any identifiable component
in the problem domain.

FAQ 5.08: A class can be thought of as a C=style function that
can maintain state between invocations in a thread-safe manner
and can also provide multiple services. If there wer exactly one
instance of a class, and all its member functions except for
exactly one public: member function were removed, the result
would be a C-style function (the object's data would correspond
to static data that is local to the function.)

However, the book Design Patterns sez to create the Flyweight Design
Pattern, you create a table of objects, each with no state.
By your own definition above (and Grady Booch's BTW) an "object" with no
state, isn't an object.
Now if I felt like implementing that pattern using a table of
function pointers, then do I don't have a "reeeeeal" Flyweight
Design Pattern??
Of course, but are the stateless things used by the pattern objects?
Or is the Standard's answer to the question "are functions objects?"
not always absolute and perfectly useful?
I don't think anyone would argue that only objects can be useful. Is the
definition useful? I think so, one needs to treat a state-full thing
differently than a stateless thing. An object different than a
non-object.

This doesn't really sound like it belongs in comp.lang.c++ though.

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 17 '06 #8
Daniel T. wrote:
How does a function have state? More spicifically how does it have more
than one state?
Well, it can only have one instance...

....so nobody said it had to have more state than instance... ;-)
>However, the book Design Patterns sez to create the Flyweight Design
Pattern, you create a table of objects, each with no state.

By your own definition above (and Grady Booch's BTW) an "object" with no
state, isn't an object.
I don't care what authority said what objects are objects - including
myself. If I want to call functions used as objects in the Flyweight Pattern
"objects", then they are. What's most important is the term is useful, not
that it's more exact or more authoritative.
>Now if I felt like implementing that pattern using a table of
function pointers, then do I don't have a "reeeeeal" Flyweight
Design Pattern??

Of course, but are the stateless things used by the pattern objects?
Uh, I think they are implemented as instances of classes. So maybe they
aren't!
>Or is the Standard's answer to the question "are functions objects?"
not always absolute and perfectly useful?

I don't think anyone would argue that only objects can be useful.
I didn't say that.
Is the
definition useful? I think so, one needs to treat a state-full thing
differently than a stateless thing. An object different than a
non-object.
How about we relax and write good OO designs.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 17 '06 #9
In article <da************ *************** *@news.west.ear thlink.net>,
da******@earthl ink.net says...

[ ... ]
How does a function have state? More spicifically how does it have more
than one state?
Usually by using a static variable. For example:

enum dir { in, out };

int rand(enum dir direction, int var = 0) {

static int seed;

if (direction == in) {
seed = *var;
return 0;
}
else {
seed *= 31415927;
++seed;
return seed;
}
}

A function can have as much state data and as many states as it wishes
(within the storag limits of the implementation, of course).

I'd also note that this is somewhat language-specific. Quite a few
languages don't support a function with state like C++ does. Some
attempt to define functions so they fit closely with the usual
mathematical definition, where the output depends only on the input.
Others allow some sort of state, but with substantial limitations, and
still others more or less arbitrary state.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 17 '06 #10

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

Similar topics

2
9592
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
7
1454
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj() <bind obj to func> return func() return wrapper()
9
3690
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
3
14929
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
7671
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
28
4307
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
5
2233
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
4
2118
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
3210
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
12
3008
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
0
8425
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
8326
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,...
0
8845
Oralloy
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...
0
8743
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
8622
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...
1
6177
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
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1736
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.