LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-20-2014, 03:11 PM   #16
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 262

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?

Quote:
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
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 262

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.

Quote:
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
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration