Pointer Assignment!! 
Author Message
 Pointer Assignment!!

guyz!!!
    I am facing a problem with pointer assignment!!
A core dump due to Segmentation Violation was generated.
Using dde (hp-ux de{*filter*}) I found these error messages
just before violation. Can you please help me with how pointer
assignments are done?

Error mesage from de{*filter*} while trying to print pointer varaible.
"cannot read from virtual address 6572747D of process 5625"
TIA

-Ravi



Tue, 22 Aug 2000 03:00:00 GMT  
 Pointer Assignment!!

Quote:

> guyz!!!
>     I am facing a problem with pointer assignment!!
> A core dump due to Segmentation Violation was generated.
> Using dde (hp-ux de{*filter*}) I found these error messages
> just before violation. Can you please help me with how pointer
> assignments are done?

> Error mesage from de{*filter*} while trying to print pointer varaible.
> "cannot read from virtual address 6572747D of process 5625"
> TIA

> -Ravi

Since you have not posted any samplings of the code that has the
problem, I can only guess at what you want help with.  So to answer your
question:

Pointer Assignment
------------------
A pointer "points" to something, whether it be an int or a structure.  A
pointer can also point to nothing, in which case it has a null value.
To make a pointer point to something, use the "&" operator:
(1)     int     length;
        int *   int_pointer;

        int_pointer = &length; /* make the pointer point to something */

This is one kind of assignment allowed with pointers.  Another is to
assign a pointer to another pointer:
(2)     int *   pointer_to_int;

        int_pointer = pointer_to_int; /*assign one to another */

A third method is incrementing or decrementing the pointer:
(3)     int_pointer++; /* point to the "next" integer */

But alas, C also allows pointer arithmetic.  This has the effect of
moving the pointer a number of types forward or backward.  The type
depends on the type associated with the pointer.

To keep your sanity, you should not mix types of pointers, such as
assigning a pointer-to-int to a pointer-to-structure.

Another way to view a pointer is as an address of a memory location. In
example 1 above, the pointer is assigned the address of the integer
"length".  Using this concept, you have to remember that the pointer has
a type associated with it.

A pointer can point to anything.  Changing where a pointer "points to"
does not cause any system errors.  Accessing the object that the pointer
is pointing to may cause an error, but that is called dereferencing
which is another topic (that you didn't ask for).  Hint:  make sure the
contents of the pointer are valid before dereferencing it.

--
Thomas Matthews



Tue, 22 Aug 2000 03:00:00 GMT  
 Pointer Assignment!!

Quote:

>guyz!!!

And gals...

Quote:
>    I am facing a problem with pointer assignment!!
>A core dump due to Segmentation Violation was generated.
>Using dde (hp-ux de{*filter*}) I found these error messages
>just before violation. Can you please help me with how pointer
>assignments are done?

char stuff[] = "stuff"; /* An array holding data */
char *p = stuff; /* Here you go. A pointer assignment */

Quote:
>Error mesage from de{*filter*} while trying to print pointer varaible.
>"cannot read from virtual address 6572747D of process 5625"

Don't try to read from that address unless you own it [you allocated it or it
is the address of an auto in your program or the address of a static object in
your program].

Quote:
>TIA

The great Karnak might be able to do better.  That's the best I can come up
with, given what you have provided.
--
Hypertext C-FAQ: http://www.*-*-*.com/ ~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.*-*-*.com/


Tue, 22 Aug 2000 03:00:00 GMT  
 Pointer Assignment!!

Quote:

> guyz!!!


Quote:
>     I am facing a problem with pointer assignment!!
> A core dump due to Segmentation Violation was generated.

You are dereferncing a pointer whose contents point outside of the memory
owned by your program. Without additional (useful) information (such as
actual source lines) your problem can't be answered better than that.

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Tue, 22 Aug 2000 03:00:00 GMT  
 Pointer Assignment!!

Quote:

> A core dump due to Segmentation Violation was generated.
> Using dde (hp-ux de{*filter*}) I found these error messages
> just before violation. Can you please help me with how pointer
> assignments are done?

> Error mesage from de{*filter*} while trying to print pointer varaible.
> "cannot read from virtual address 6572747D of process 5625"

        Well, I would say that this error message means that a failed attempt
was made to read from virtual address 6572747D (presumably the virtual memory
address of the pointer you were trying to print) and that it belongs to a
process with ID 5625 hex.

        Obviously, anything you do with the pointer after this situation
occurs will cause a segmentation fault.

        Now (heh heh)... that's not enough information to solve anything!  :)

        Therefore, (and the next time you run the program those values are
more than likely to change), I'd recommend going back and debugging it all
over again.  This time, identify the process (is it your process, is it
a system or kernel process, is it one process of a multi-process application,
is that process waiting for an event or signal?).  Then trace back through
the pointer variable's recent history, to see if it was invalidated, or could
possibly have been invalidated, or has passed out of scope.

        Then, if there is any C code that you believe is suspicious, post it.

                                                        -- Stone



Wed, 23 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. pointer to pointer assignment

2. pointer assignment

3. pointer assignment

4. void pointer assignment problem

5. NULL pointer assignment

6. Function pointer assignment problem

7. null pointer assignment

8. C - Null Pointer Assignment

9. pointer assignment

10. Null pointer assignment

11. Structure pointer assignment

12. NULL pointer assignment

 

 
Powered by phpBB® Forum Software