473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C objects

What is a C object ?

If i have some function "func()" in my C program, then
can i say that "func()" is a C object ?
or if i have some function pointer (ptr) which contains the address
of function "func()", can i say that ptr is pointing to some C object ?

Is a C object always associated with some "data" ?

thanx in advance for any help .....
Nov 14 '05
115 4904
Flash Gordon <sp**@flash-gordon.me.uk> writes:
[...]
2) If the implementation might place the start of a function at all bits
0 then I believe 1 above applies again because a pointer to a function
has has to be distinct from the null pointer.

[...]

A small quibble:

A function pointer doesn't necessarily contain the address of the
start of the function. It could be, for example, an index into a
table. Also, a null function pointer doesn't have to have the same
representation as a null object pointer. You could have null object
pointers represented as all-bits-zero, null function pointers
represented as all-bits-one, and a valid function (main?) starting at
address all-bits-zero. (And of course code and data could be in
separate address spaces.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #111
Keith Thompson wrote:
CBFalconer <cb********@yah oo.com> writes:

[...]

That was UCSD Pascal, which is not representative.


(Actually it was a derivative of UCSD Pascal.)

Not representative of what?


Proper ISO (or even J & W) compliant Pascal. Influential, though.

--
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 #112
On Tue, 17 Aug 2004 14:17:49 -0700, E. Robert Tisdale wrote:
Mabden wrote:
E. Robert Tisdale wrote:
I believe that, currently, *all* viable C compilers
use all-bits-zero for NULL
so this is something that you don't need to worry about.


But I am assured this is not the case! You may NOT use the word "ALL".


Please cite an example of a standard conforming C compiler
that does *not* use all-bits-zero for NULL.


http://www.eskimo.com/~scs/C-faq/q5.17.html

Amazing what you can find by reading the FAQ.
Nov 14 '05 #113
Kelsey Bjarnason wrote:
E. Robert Tisdale wrote:
Mabden wrote:
E. Robert Tisdale wrote:

I believe that, currently, *all* viable C compilers
use all-bits-zero for NULL
so this is something that you don't need to worry about.

But I am assured this is not the case! You may NOT use the word "ALL".


Please cite an example of a standard conforming C compiler
that does *not* use all-bits-zero for NULL.


http://www.eskimo.com/~scs/C-faq/q5.17.html

Amazing what you can find by reading the FAQ.


I don't believe that any of these platforms ever supported
a "standard conforming C compiler".
Nov 14 '05 #114
In Mon, 16 Aug 2004 06:48:19 GMT, Keith Thompson <ks***@mib.or g>
wrote:
<snip>
Function pointers and object pointers are different things; in
particular, you can't legally convert one to the other. In some
implementations , object pointers and function pointers aren't even the
same size. (An implementation could legally implement an object
pointer as a raw machine address, and a function pointer as an integer
index into a table of functions; I don't know of any that actually do
this.)

I can give you one, though obscure and arguably obsolete: classic but
still used in emulation Tandem^WCompaq^ WHP NonStop aka TNS.

The (1970s proprietary) ISA defined originally two code segments --
one "user" (application) per process, one "system" (OS) shared -- each
with an entry point aka PEP table at the beginning containing 2
overhead (16-bit) words followed by up to 510 procedure addresses
(16-bit within segment). The (app) call instruction PCAL contained a
9-bit index, as did system call SCAL. BTW their OS was effectively a
nanokernel design, long before that term existed, so most of the OS
functionality was and still is actually in the "user code" segments of
various system processes, not in the "system code" segment.

Over time they added a second shared/OS "library" segment with a third
instruction LCAL, then an additional per-process "user library"
segment at which point they changed the PCAL instruction to index into
a second per-segment *exit* table at the end somewhat confusingly
called external entry point aka XEP, each entry a 16-bit word itself
containing 2 bits selecting the target segment plus 9 bits indexing
into the PEP table thereof. Then finally they used 4 of the remaining
bits of the XEP word to allow multiples of each segment type (user,
user library, system, system library).

And there was a separate indirect call instruction DPCL which now
takes that XEP word format; I forget if it originally took a "system"
bit (plus index) or was limited to user code. So to make a long story
not short enough, that XEP word format is the function pointer for C.

The data segments are also separate, again originally one "user" per
process and one "system" shared but accessible only by privileged
(normally system) code. The original 16-bit (TNS1) memory model is
still available as an option, restricted to less than 64KB*; in the
32-bit (TNS2) memory models, data pointers are 32-bit (mostly, with
some further hacks, and can access some code sometimes for readonly
but not for execution) and function pointers are 32-bits with the
upper 16 as above and the lower 16 not used (zero). While the C
standard allows function and data pointers to be different sizes as
well as different representations , Tandem did only the latter; I'm not
sure why. Perhaps just convenience. As long as you don't have huge
numbers (perhaps arrays) of function pointers, which I've never seen
anyone do, the space wastage is minor.

So using a converted or punned function pointer for a data access may
get you data completely unrelated to the function but more likely a
fault; while similarly using a data pointer for a function call will
get you either a valid function, having nothing to do with the data,
or a fault (segment or index out of range). PEP index zero is never
used, so a zero XEP word can be the null function pointer.

* As I've previously posted, TNS1 actually has two data pointer forms
-- one for byte/char=8-bit, and one for everything else, which must be
word=2-byte aligned, so in that environment you can't just treat all
data pointers as void*. The *ISA* supports 64KW = 128KB. But the HLL
runtime reserves the upper 32KW, hence *in C* only 32KW = 64KB of data
less some overhead, including as I've recently posted RTL-sacred data
always at data address 0 allowing that to be the null data pointer.

And in another oddity, the TNS stack grows upward, so the
"local" stack smashes too common in C on most other machines are
harmless -- they just run off into unused memory. It is still possible
to clobber the stack if you overrun a buffer in the (or a) *caller*'s
frame, or in some cases a "global" aka static-duration one, but this
is usually harder to provoke or control. And even if you do, you flat
cannot execute code from data space; the most you can do is redirect
to existing code somewhere. Or crash the process; or if you could
manage it in system code in the days of real hardware TNS, less likely
as the system code then wasn't in C and never used null-terminated
strings, maybe crash the CPU. (Current "TNS/R" systems emulate classic
TNS only in userspace, optionally, not system.)

Multics also had a code segment format that restricted in-calls to
(via) entries in a small, checked table, but I don't recall exactly
how the pointers worked, and in any case it no longer exists. I don't
believe it ever had a C, especially in view of C's historically strong
and originally exclusive connection with Unix.

- David.Thompson1 at worldnet.att.ne t
Nov 14 '05 #115
On Tue, 17 Aug 2004 10:20:02 GMT, "Mabden" <mabden@sbc_glo bal.net>
wrote:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... <snip>
I've just looked up the word "object" in the indexes of K&R2 and H&S5
(that's Harbison & Steele, 5th edition). Both define the term in a
manner consistent with the definition in the standard; both make it
clear that a function is not an object. <snip>

I think the term "object" has changed meanings since C++ came about. In K&R,
it seems to me that almost any memory location can be called an "object". In
such a case, a pointer is an object and a function name, like an array name,
can be distilled down to be called an object.

Does Appendix K&R2 A7.1 not hint at this?

My K&R2 went missing some time ago, but the C standard specifically
says "region of _data_ storage" (emphasis added). Note it doesn't
require addressibility; this includes variables (aka named objects)
put in machine registers, possibly but not necessarily by declaring
them with storage class 'register'.

On (essentially?) all computers today compiled code for functions is
in fact stored in memory; and on most of them at least some of the
time that memory is addressible in the same way as data. *In those
environments* a C compiler usually(?) allows you to interchange
function and data pointers, and there can sometimes be good reason to
do so, although it's not portable and often virtual memory is set up
so that you cannot *write* to function addresses.

But C intentionally does not require this. In fact one of the quite
early "ports"* of C -- long before C89 and K&R2 -- was to models of
the PDP-11 with separate "instructio n" (code) and data space, called
"split I&D" and more generally known as "Harvard architecture". On
those machines the code to dereference a data pointer simply cannot
access code, and that to dereference (call) a function pointer (or
call an actual function, the more common case) simply cannot access
data; in assembler you can access code as data with special
instructions, MFPI/MTPI, subject IIRC to privilege, but the compiler
doesn't know to generate them. * "Port" in quotes because the compiler
can generate the same instructions and data as for nonsplit -11s; the
only difference is a tweak in the linker, and of course some changes
in the VM in the underlying OS, which isn't normally considered part
of the C implementation although in a formal sense it is.

<OT> And it hasn't changed officially even *in* C++ -- which still
uses 'object' in the C meaning, and for the things that OO people call
'object' it consistently uses (often clumsier) forms like 'object of
class type', 'class object', or more specific things like 'object of
non-POD class type having a nontrivial constructor'. </>

- David.Thompson1 at worldnet.att.ne t
Nov 14 '05 #116

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

Similar topics

2
8252
by: dasod | last post by:
I would like to know if my method to remove list objects is correct in this small test program. It seems to me that there might be a simplier way, but I'm afraid I don't know enough about list iterators and how they are behaving in situations like this. #include <iostream> #include <list> class Test; typedef std::list< Test* > Tlist;
9
1888
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. Here's the question: I want to be able to change the references (including deleting them). Is there any way to do that besides using pointers rather than references for the STL library? I'd also prefer to avoid using const_cast, if it is indeed...
6
2576
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically, I want to store classes of my objects in a vector. I also have three further questions:
3
3029
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements - also allow them? Adding (and removing) object properties dynamically is an acceptable and common practice in JavaScript, and greatly adds to the power and character of the language. Essentially, an object in JavaScript can be considered to...
8
1862
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
161
7851
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
7
8222
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
21
2210
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not necessarily the same... class base { int x;
27
2561
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the Standard is saying that "object is a region of storage", I deduce from that that literal constants aren't objects because they may not be alocated as regions of storage in the memory.
14
6022
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared static inside functions (i.e. local static objects) 5. objects declared at file scope.
0
8946
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
9449
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...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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
6735
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
6031
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
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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

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.