Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-20-2014, 03:11 PM   #16
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 133

Original Poster
Rep: Reputation: Disabled

To quote Bjarne Stroustrup, "The better one knows C, the harder it seems to avoid writing C++ in C style." Definitions in the OpenGL Programming Guide (the Red Book) C: God's programming language. C++: The programming language of an alien deity. My own spin is that for a project written by a single programmer, C is easier. For a project written by multiple programmers in parallel, C++ is almost mandatory. However, that is a topic for a different thread. Relevant to this thread, does .size return something other than 8? If not, then why not?

Originally Posted by rtmistler View Post
I don't know the exact code syntax, but C++ is eminently better qualified to manage lists and arrays; similarly is python. For instance, just me tossing it out having not checked, you have a list declared, you also have methods for it such as .size() or .length(), I believe it would be .size() where that will give you an integer representation of the size of the list. Further, the greater part of C++ is that things like String types or something similar; classes actually; allow you to declare something as a String class or list of String classes and not worry about pre-declaring the dimensions. So you might want to keep what you do have, but look a bit at some of the available C++ classes you could use.

And to note further, gcc on a general Linux system should be able to deal with C++ code. Not sure if you're working on that type of platform, but just pointing that detail out.
Old 03-20-2014, 03:38 PM   #17
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 133

Original Poster
Rep: Reputation: Disabled
If I ask for sizeof(subtopic_3), it returns 16. If I ask for (sizeof(subtopic_3) / sizeof(char *)), I get the number of elements in the array.
Since sizeof(subtopic[i]) returns 8 for all [i], apparently it does not recognize that subtopic[i] is an array.

Originally Posted by ntubski View Post
sizeof returns size in bytes, your size[] array is counting the number of elements. subtopic is an array of pointers, all pointers are 8 bytes (or 4 bytes on a 32 bit system).
Old 03-20-2014, 06:00 PM   #18
Senior Member
Registered: Nov 2005
Distribution: Arch
Posts: 3,103

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Originally Posted by piobair View Post
apparently it does not recognize that subtopic[i] is an array.
That's because subtopic[i] is not an array. Consider that subtopic_0 is not the same size as subtopic_1, they have different size (and therefore different types). An array's elements must be of the same type (and therefore same size). To get around this restriction you made subtopic into an array of pointers; it doesn't contain arrays.

The distinction between arrays and pointers in C is confusing, the C FAQ's Arrays and Pointers section and this other LQ thread about it may be useful reads.


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
perl - multidimensional array toredo Programming 3 06-11-2010 08:29 AM
Perl multidimensional array zhjim Programming 9 08-21-2009 09:59 AM
Initializing Array of Strings jrtayloriv Programming 10 02-03-2005 12:22 PM
How to allocate memory for a multidimensional array ? indian Programming 12 11-19-2004 03:37 AM
multidimensional array (php) niehls Programming 2 01-31-2003 05:34 AM

All times are GMT -5. The time now is 08:52 PM.

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