473,769 Members | 5,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointers with C- a query

Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows java
able to do this with out pointers?
I jus plead sorry to those who advice me to post it to java people
because I have already done it.
Jus want to know alternatives to pointers which can be used with
C.While pointers provide flexibility most bugs are with respect to
pointers.So will it not be good if we are able to either forgo the
pointers or do some sort of modification(I am not aware how,but it can
be considered for research) so that our s/w s are more pure with out
bugs?

I am sorry for my amature query,but it will be helpful and I will be
thankful to all who makes me understand this.
Regards,
s.subbarayan
Nov 14 '05 #1
19 1631
s.subbarayan wrote:
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?


Why in the world would anyone want to? Your question is similar to
asking "why don't people just cut off their left arms?".

Nov 14 '05 #2
s.subbarayan wrote:
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows java
able to do this with out pointers?
I jus plead sorry to those who advice me to post it to java people
because I have already done it.
Jus want to know alternatives to pointers which can be used with
C.While pointers provide flexibility most bugs are with respect to
pointers.So will it not be good if we are able to either forgo the
pointers or do some sort of modification(I am not aware how,but it can
be considered for research) so that our s/w s are more pure with out
bugs?

I am sorry for my amature query,but it will be helpful and I will be
thankful to all who makes me understand this.


When you pass around objects in a Java program you're actually
passing around 'pointers' (references). In Java you don't write
the * and & as you would do in C because working with 'pointers'
has been built into the language.

I would argue that it is impossible to write well structured C
programs without using pointers. There are several applications
for pointers, which are hard/stupid to implement without:

a. Passing large chucks of data to functions (avoiding making
local copies.
b. Passing data to a function to be modified inside.
c. Various 'object-oriented' programming techniques using function
pointers.
d. Creating variable size data-structures like trees, lists, ...
e. ...

Perhaps we could say that imperative programming languages do well
with an abstract representation of a memory address (which 'is' a
pointer)? Well at least this might result in some interesting
responses. ;-)

Kees alias Case

Nov 14 '05 #3
On 21 May 2004 06:06:01 -0700, s_**********@re diffmail.com (s.subbarayan)
wrote:
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows java
able to do this with out pointers?
Java is an object-oriented language, and uses the "reference" type to refer
to objects. Primitive types are handled more-or-less the same way as they
are in C. Thus there's a dichotomy in Java: objects gets referred to only
via references (to facilitate performance and garbage collection), while
stand-alone ("naked") primitives are referred to directly by name, as in C,
for performance reasons (note there's no garbage collection for naked
primitives.). Primitives in Java rarely need to be accessed indirectly;
when they do, you in fact have to wrap them in an object and then use a
reference to that object.

C, on the other hand, has only one mechanism to refer to data indirectly,
and that's the pointer. It is the only game in town; it reflects well C's
nature of being "close to the machine", and allows the use of indirection
with or without dynamic allocation, and even with garbage collection if you
take the trouble to set up a custom framework for it. Pointers are the most
general-purpose way to do it, and provided the facilities necessary to make
C the first viable high-level (relatively speaking) systems programming
language. If you modified C to "remove pointers", it wouldn't be C any
longer. C++, for example, provides its own distinct flavor of reference
type, suitable for off-loading a number of things that, in C, have to be
done with pointers. But references aren't a universal replacement for
pointers even in C++.
I jus plead sorry to those who advice me to post it to java people
because I have already done it.
Jus want to know alternatives to pointers which can be used with
C.While pointers provide flexibility most bugs are with respect to
pointers.So will it not be good if we are able to either forgo the
pointers or do some sort of modification(I am not aware how,but it can
be considered for research) so that our s/w s are more pure with out
bugs?
The potential for pointer bugs is just the price you pay for the low-level
control C gives you. It is essentially a choice (made by /someone/, if not
you personally) regarding what language to use. If you need the greatest
possible "micro-management" of your application's behavior, you end up
using C. If you're willing to pay some price (in terms of either
performance, or learning curve struggles, or code size, or whatever), you
might choose to use a different language such as Java or C++ or Python or
something else.
-leor

I am sorry for my amature query,but it will be helpful and I will be
thankful to all who makes me understand this.
Regards,
s.subbarayan


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #4
s.subbarayan wrote:
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows java
able to do this with out pointers?
Java is not "able to do this without pointers". Anything derived from
Object _is_ represented as a pointer (under a different name) in Java.
If you follow a null reference, you get an exception in Java.
I jus plead sorry to those who advice me to post it to java people
because I have already done it.
Jus want to know alternatives to pointers which can be used with
C.
You could make _every_ object a pointer and get rid of the syntactic
differences between "pointer to user defined type" and "user defined
type" in a language similar to C. Just forbid storage class "auto"
for anything that is not a primitive built-in type.
While pointers provide flexibility most bugs are with respect to
pointers. So will it not be good if we are able to either forgo the
pointers or do some sort of modification(I am not aware how,but it can
be considered for research) so that our s/w s are more pure with out
bugs?


Forbid pointer arithmetic, add bounds checks to array access? Forbid the
use of types without a specifed (and matching) range as array indices?
Make free() take a pointer to the pointer to be disposed, and keep a
list of all pointer variables in your program so that free can set
the pointer _and all other pointer variables holding the same value_
to a trap representation? Forbid type casts on pointers?

While we are at it: Add explicit preconditions and postconditions
to functions. Add explicit conditions for validitiy to every user
defined type and make the language check those before and after every
use of an object of the user defined type. Make loop variants explicit.
Make loop invariants explicit.

And, last but not least: Change the name of the language. C is a language
that does not make you pay for things you don't need. If you need them,
you can implement them in C, and pay for them.

Kurt Watzka
Nov 14 '05 #5

"s.subbaray an" <s_**********@r ediffmail.com> wrote in message
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows > java able to do this with out pointers? All computer programs need to address memory (ie use pointers) internally. C
makes this fairly transparent to the user. Other languages hide the
underlying operation, at the cost of usually making code slower, but with
the advantage that it is less easy to access memory illegally.

You could try writing a "C--" (without pointers). When you try to write real
programs with it you will probably find that you need at the very least an
expandable array, and probably a "reference" scheme as well.
Nov 14 '05 #6
Malcolm wrote:
"s.subbaray an" <s_**********@r ediffmail.com> wrote in message
Dear all,
I had this following doubt,while java is able to carryon with out
pointers why C language cant be modified to remove pointer?Hows > java


able to do this with out pointers?

All computer programs need to address memory (ie use pointers) internally.


Off-topic nit: Alan Turing demonstrated that this is false.

--
Er*********@sun .com

Nov 14 '05 #7
Eric Sosman <Er*********@su n.com> writes:
Malcolm wrote:
All computer programs need to address memory (ie use pointers)
internally.


Off-topic nit: Alan Turing demonstrated that this is false.


Even a Turing machine has a "pointer" as a part of its state: the
current tape position.

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #8
On Fri, 21 May 2004 18:51:57 +0100, Malcolm wrote:
You could try writing a "C--" (without pointers).


The name 'C--' is already in use: It's a language even lower-level than C
that is being touted as a compiler backend language.

http://www.cse.ogi.edu/PacSoft/projects/C--/

--
yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
To email me, rot13 and convert spelled-out numbers to numeric form.
"Makes hackers smile" makes hackers smile.

Nov 14 '05 #9

In article <cu************ *@zero-based.org>, Martin Dickopp <ex************ ****@zero-based.org> writes:
Eric Sosman <Er*********@su n.com> writes:
Malcolm wrote:
All computer programs need to address memory (ie use pointers)
internally.


Off-topic nit: Alan Turing demonstrated that this is false.


Even a Turing machine has a "pointer" as a part of its state: the
current tape position.


An n-PDA (n > 1) is equivalent to a TM. I don't see any pointer-
equivalent in an n-PDA.

Pointers aren't necessary. They're just very convenient. And to
answer the OP's question: if pointers were removed from C, it would
no longer be C.

--
Michael Wojcik mi************@ microfocus.com

HTML is as readable as C. You can take this either way. -- Charlie Gibbs
Nov 14 '05 #10

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

Similar topics

9
3094
by: Neil Zanella | last post by:
Hello, Some programmers like to use a coding convention where all names of variables that are pointers start with the letter p (and sometimes even use similar conventions for strings and other numeric data types). Do such programmers also have conventions for naming structures and unions (e.g. do they like their names to begin with s and u, so that, when the . operator is used, it is clear whether a structure or union is being accessed...
2
1312
by: DirtyClamDigger | last post by:
Hi Everyone: I'm trying to develop a property list to include as metadata about my object classes. i.e. I want each class I'm developing to include a PropertyList which will contain ObjectProperty pointers. ObjectProperty is a class containing the typeid.name() of a type as it's ObjectType as well as an ObjectName and ObjectDescription. Basically 3 strings of metadata describing each of a class' member variables (and hopefully functions)...
1
2555
by: Scott McFadden | last post by:
What is the proper way to pass pointers by reference from managed c++ calls to native c++ calls? In managed C++, I have a pointer to an array of structures, that I pass to a native c++ method by reference: //Managed c++ QueryResult* qr = NULL; ExecuteQuery(1, "abc", qr); //invoke native c++ method passing qr by reference
10
1593
by: dbz | last post by:
Hello everyone. I have a query. Lets say that following is given:- struct struct1{ char *word; int n; } *p; QUERIES: What does the following refer to?
8
2101
by: Ivan Liu | last post by:
Hi, I'd like to ask if passing an object as an pointer into a function evokes the copy constructor. Ivan
16
1551
by: ajinkya.coep | last post by:
What's wrong with this program? If you were to fix it, what would the intended output be? void swap(char *str, int index1, int index2) { char tmp = str; str = str; str = tmp; } int main(int argc, char *argv) {
158
9093
by: madhawi | last post by:
This question is occur in interview. Please help me.
22
1981
by: ravi | last post by:
Hi all, I m relatively new to C. I have few queries related to malloc(): 1. When we perform malloc(), the memory allocated dynamically comes from the heap area of the process in concern. Well, we then say that the heap has shrinked. my query is: Is it that the heap physically does not shrink but the perticular nodes are marked 'ALLOCATED' and for subsequent calls to malloc() the memory manager remembers them and does not reference...
69
3208
by: Yee.Chuang | last post by:
When I began to learn C, My teacher told me that pointer is the most difficult part of C, it makes me afraid of it. After finishing C program class, I found that all the code I wrote in C contains little pointers, obviously I avoid using them. A few days ago when I was reading a book about programming, I was told that pointers are the very essence of C language, if I couldn't use it well, I'm a bad programmer, it's a big shock. So now I'm...
0
9579
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
9416
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
10199
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
10032
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...
1
9979
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
9849
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
7393
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
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2810
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.