LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-23-2007, 08:28 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
syntax for gdb to print elements of 2D array?


Hi.

The syntax for gdb to print all the elements of a 1-D array is:
Code:
 
(gdb) p myArray
and to print the next 5 elements of array myarray starting at element 3, say, is:

Code:
(gdb) p myIntArray[3]@5
Can anyone tell me the syntax to print elements when you go beyond a 1-D array?

Thanks
 
Old 03-24-2007, 08:37 AM   #2
zWaR
Member
 
Registered: Dec 2003
Distribution: Slackware, Alpine Linux, Ubuntu, Debian
Posts: 219

Rep: Reputation: 35
I don't know the gdb's syntax, but perhaps you could help yourself with ddd (if you're running X), it's actually a really sophisticated GUI for gdb, which can also graphically display the arrays and it displays the gdb commands it uses.

http://www.gnu.org/software/ddd/
 
Old 03-26-2007, 06:27 AM   #3
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
Thanks for that...but Suse(this and previous version anyway, I think!) is missing a certain Motif file Xm needed to build the GUI. I've come across this problem before trying to install another GUI program. I could install the Lesstif package in it's place but don't think it's worth the trouble for all I need to do...

So if anyone does know the command line gdb syntax for checkin gthe elements of a multi-dimensional array?

thanks
 
Old 03-26-2007, 07:20 AM   #4
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
ok. I think the syntax is:

Code:
print array(2,3)
- for example to entry (2,3) of array array...

but I can't check this because my array is messed up!

entering

Code:
ptype myarray
into gdb returns the type of the array and the dimension of the array...is this right?

doing this for the array that I am trying to get at gives:

Code:
(gdb) ptype bderi
type = real*8 (0:-1,0:-1)
I assume the (0:-1,0:-1) refers to the extents of the array - here a bit wacky!

Can anyone confirm this?
 
Old 03-26-2007, 07:24 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
if you do a lot of C programming
ddd is definitely worth it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simultaneous writes into different elements of an array estratos Programming 7 12-15-2006 06:36 AM
Passing Array Elements to functions melikai Programming 4 10-31-2006 10:27 PM
Renaming array elements in bash bryan.out.there Programming 2 05-31-2006 11:44 PM
odd behaviour of array elements in c++ markhod Programming 4 03-14-2005 09:58 AM
perl - get number of elements in an array AM1SHFURN1TURE Programming 3 03-07-2005 03:59 PM


All times are GMT -5. The time now is 03:15 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration