Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What's the disadvantage of using pointers in C?

Status
Not open for further replies.
Re: c

the one disadvantage i know is that if you make a mistake while handling pointers it may even lead to the crashing of your system....
 
Re: c

sundarmeenakshi,
The most insidious errors occur with uninitialized pointers. Suppose a pointer has some random value. You store data and retrieve it using the pointer.
1) *pointer = x.
2) x = *pointer.
This works fine as long as the (random) address represented by the pointer is not used for anything else. If the address is used for something else, then that data (or instruction) at the location represented by the pointer will be destroyed by the the execution of instruction 1 above. Now, here comes the fun part: Suppose you insert a printf statement to try to debug the problem. After recompilation, the random address represented by the pointer is used to hold another piece of data or instruction, and the original problem disappears, only to reappear somewhere else in your program.
.
The use of pointers requries discipline. The number one rule is "aways initialize pointers". If you're lucky, your complier will initialize the pointer value to null (zero), which will result in a run-time error in most environments.
Regards,
Kral
 
Re: c

Thier would be disadvantages of pointers if you are not handling them properly.
And in some cases might not be easier to debug.
 
Re: c

they are easy to understand but not to use properly.

if you are giving a struct into a function parameter and if that struct is big, using a pointer you´ll use less memory for the program, running it faster.

the same occurs with arrays.

i think pointers are essential for a programmer because of speed and size.
 
c

Pointers are very powerful allowing you to write fast and efficient code. They are one of the strengths of the C language. C code without pointers is like beer without alcahol, plenty of body, but no oomph.
There are no disadvantages to pointers in C.
 
Re: c

i would advice btbass to take a through look at whatever book he is studying.... when a pointer is not properly intialised or properly handled you can rest assured that something bad would happen to ur PC.... a program is supposed to be safe under all circumstances....
 

Re: c

if pointer has started pointing toward system reserved memory then it may cause sytem unstability.

like windows has a specific area in RAM reserved for OS, if a pointer makes cahnges to this area then it will be a virus like operation. as some funny things open our cd rom, that is just by accessing this area
 
c

It is just as easy to screw up any aspect of a program, using unintialised variables, mixing signed and unsigned integers, not catching exceptions, pointers are no easier to screw up than any other feature. Pointers help you to write elegant efficient code.
When I write a program for a pc, I use c#, a modern programming language that overcomes a lot of the oversights that are easy to miss.
But a lot of programming involves 8 bit micros, and C is king for this type of application.
I also use static analysis of my code using lint.
Lint will find all sorts of obscure bugs. If your code is crashing because of uninitialised pointers, that is not the fault of C! But your lack of proper testing.
Using pointers should be encouraged, they give c its edge.
 

Re: c

You also need to make sure you reference and dereference them propoerly, otherwise you'll be using the address instead of the data.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top