Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Pointers to elements in a Double-Linkedlist

Reply
Thread Tools

Pointers to elements in a Double-Linkedlist

 
 
Paminu
Guest
Posts: n/a
 
      02-13-2006
I am implementing a double-linkedlist in C. I have defined some pointers
that points to different locations in my list. Before using the list I will
initialize these pointers and when I call insert/delete etc they will be
changed.

Instead of giving each funtion these pointers as argumentens I was wondering
if it was possible to place them i a .h file and initialize them there. When
a function changes the pointers they will be updated in the .h file which
will always contain the most updated version of the pointers.

Is this possible?

Johs


 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      02-13-2006
Paminu wrote:
>
> I am implementing a double-linkedlist in C. I have defined some pointers
> that points to different locations in my list. Before using the list I will
> initialize these pointers and when I call insert/delete etc they will be
> changed.
>
> Instead of giving each funtion these pointers as argumentens I was wondering
> if it was possible to place them i a .h file and initialize them there. When
> a function changes the pointers they will be updated in the .h file which
> will always contain the most updated version of the pointers.
>
> Is this possible?


Possible, but inadvisable. You should NEVER define data in a .h
file. The purpose of the header file is to define the access to
your module given to other modules. Thus is will necessarily be
included in more than one compilation unit, and any data
definitions will result in multi-defined errors.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943


 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      02-14-2006
On Mon, 13 Feb 2006 09:23:26 +0100, "Paminu" <> wrote:

>I am implementing a double-linkedlist in C. I have defined some pointers
>that points to different locations in my list. Before using the list I will
>initialize these pointers and when I call insert/delete etc they will be
>changed.
>
>Instead of giving each funtion these pointers as argumentens I was wondering
>if it was possible to place them i a .h file and initialize them there. When
>a function changes the pointers they will be updated in the .h file which
>will always contain the most updated version of the pointers.
>
>Is this possible?


Possible, yes. Desirable, probably not.

..h files, as the term is used in C, are used during compilation, not
during linking and not during execution.

Most of the experienced contributors recommend not placing object or
function definitions in a .h file, only declarations, typedefs, macro
definitions, etc. If your program has multiple source files that
include the .h files and you put the pointer definitions and
initialization in the .h file, then when you link the multiple object
modules the linker will report multiple definitions of the pointers.

If you want to establish the pointers as global variables so that all
of your functions have access to them, the preferred approach is to
declare them as EXTERN in the .h file, define them in the source file
containing main(), and #include the .h file in every source module.
However, the conventional wisdom is avoid globals unless absolutely
necessary.


Remove del for email
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Does deleting a container of pointers also delete the (contained) pointers? Xamalek C++ 7 11-04-2003 04:17 PM
c++: pointers to pointers A C++ 3 10-29-2003 01:15 PM
pointers to pointers // exception handling error muser C++ 3 09-18-2003 06:19 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57