473,785 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

semantic difference between [][] and **

Say I have:
char foo[][];
char** bar;

In my understanding, these two have the same meaning in memory.
Could someone elucidate upon these two types and their meanings?

Thanks,
Paul
Jul 22 '05 #1
7 1605
Paul wrote:
Say I have:
char foo[][];
char** bar;

In my understanding, these two have the same meaning in memory.
What is "meaning in memory"?
Could someone elucidate upon these two types and their meanings?


The former, IIUIC, is an error, since to declare a multidimensiona l array
you have to specify all sizes but the inner-most one.

V
Jul 22 '05 #2
char foo[][]; is an invalid declaration. Only the first dimension size
can be omitted, and even then you're expected either to be using a
declaration without the definition, or initializing the array such that
the size can be calculated from the initializer.
these two have the same meaning in memory.

Not necessarily. Perhaps if you post some more code, and mention what
system and implementation you're using, a more thorough answer can be
given.

-Ren

Jul 22 '05 #3
Ren
char foo[][]; is an invalid declaration. Only the first dimension size
can be omitted, and even then you're expected either to be using a
declaration without the definition, or initializing the array such that
the size can be calculated from the initializer.
these two have the same meaning in memory.

Not necessarily. Perhaps if you post some more code, and mention what
system and implementation you're using, a more thorough answer can be
given.

-Ren

Jul 22 '05 #4
Victor Bazarov wrote:
Paul wrote:
Say I have:
char foo[][];
char** bar;

In my understanding, these two have the same meaning in memory.


What is "meaning in memory"?
Could someone elucidate upon these two types and their meanings?


The former, IIUIC, is an error, since to declare a multidimensiona l
array you have to specify all sizes but the inner-most one.

They way they are written, those are variable declarations, not
function parameters, so the first case would have to be initialized as
well.

char foo[][6] = {"one", "two", "three"};

Then the compiler can count the initializers and compute the missing
dimension.

Now, if used in a function declaration, then you can have:

void bar (char foo[][6]);

It's definitely not equivalent to:

void bar (char **foo);


Brian

Jul 22 '05 #5
ma*********@acm .org wrote:
char foo[][]; is an invalid declaration. Only the first dimension size
can be omitted, and even then you're expected either to be using a
declaration without the definition, or initializing the array such that
the size can be calculated from the initializer.

these two have the same meaning in memory.


Not necessarily. Perhaps if you post some more code, and mention what
system and implementation you're using, a more thorough answer can be
given.

-Ren

Let's say:

char foo[16][16];
char **bar;

bar = new char*[16];
for(int i = 0; i < 16; i++)
{
bar[i] = new char[16];
}
It is my understanding that foo and bar can be accessed and passed
around in similiar manner and maintain the same meaning.
I also think they can be cast from one to the next without error.

I have a suspicion I'm wrong, however. :-)

-Paul
Jul 22 '05 #6
Paul wrote:
ma*********@acm .org wrote:
char foo[][]; is an invalid declaration. Only the first dimension size
can be omitted, and even then you're expected either to be using a
declaration without the definition, or initializing the array such that
the size can be calculated from the initializer.

these two have the same meaning in memory.

Not necessarily. Perhaps if you post some more code, and mention what
system and implementation you're using, a more thorough answer can be
given.

-Ren

Let's say:

char foo[16][16];
char **bar;

bar = new char*[16];
for(int i = 0; i < 16; i++)
{
bar[i] = new char[16];
}
It is my understanding that foo and bar can be accessed and passed
around in similiar manner and maintain the same meaning.


Similar, maybe. Same meaning, no. Same purpose, perhaps.
I also think they can be cast from one to the next without error.
That's incorrect.
I have a suspicion I'm wrong, however. :-)


Yes, unfortunately, you are. 'foo' is an array of arrays, while 'bar'
is [a pointer to] an array of pointers. They have different types and
therefore behave differently in certain situations. Also, the derived
objects, *bar and *foo have different types, although now they are more
compatible than before, you may convert decltype(*foo) to decltype(*bar).
[Note: I use 'decltype' to convey the meaning, there is no such construct
in C++ yet].

The important difference (and that's where casting comes into play) is
that the memory layouts of what is designated by 'foo' and by 'bar' are
vastly different.

V
Jul 22 '05 #7
Paul wrote:
ma*********@acm .org wrote:
char foo[][]; is an invalid declaration. Only the first dimension
size can be omitted, and even then you're expected either to be
using a declaration without the definition, or initializing the
array such that the size can be calculated from the initializer.

these two have the same meaning in memory.
Not necessarily. Perhaps if you post some more code, and mention
what system and implementation you're using, a more thorough answer
can be given.

-Ren

Let's say:

char foo[16][16];
char **bar;

bar = new char*[16];
for(int i = 0; i < 16; i++)
{
bar[i] = new char[16];
}
It is my understanding that foo and bar can be accessed and passed
around in similiar manner and maintain the same meaning.


Accessed, pretty much yes. Passed? Absolutely not.

http://www.eskimo.com/~scs/C-faq/q6.18.html
I also
think they can be cast from one to the next without error.


You can cast the array to the pointer and it won't cause an error
(because you did a cast). Doesn't mean it will work. The two constructs
will have different layouts in memory, and the pointer strides are
different. The name of array is converted to type pointer to array 16
of char.

Just disabuse yourself of this notion. Read ALL the FAQs on arrays and
pointers in the C FAQ (it's more useful for these questions).

Brian
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
2983
by: Darren Dale | last post by:
I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what open source is all about, isnt it? I even have a copy of visual studio, and I still cant build modules from source, because my academic copy is version 7. As a scientist funded by the NSF, I feel compelled to do all my work using free software (I...
5
6089
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the Internet. Specifically, marking up a document that will contain multiple related form controls (intended exclusively for client-side scripting) that would never be intended to be submitted. I realise that that concept is a non-starter in an Internet...
3
1678
by: pr10n | last post by:
Hello, all! I'm working on a personal blog and I'm trying to make it's markup more semantic, using the right elements, removing needless div's and so on. I was wondering if someone would be kind enough to peek at the code and see if they have any suggestions. I realize I am over using the list and header elements. I am also in the process of shifting the content blocks around in the code to get the meat of the site displayed first. ...
2
1640
by: dayzman | last post by:
Hi, I'm in need of a program that extracts the semantic structure of HTML pages -- a program that groups paragraphs with the corresponding headings etc. I know it's not too difficult to extract well structured documents, e.g. formal essays. However, with complicated sites like CNN and CNet, where many tables are used to align text, to me it'd become extremely difficult. Does anyone know of any existing applications? If not, should it be...
3
1667
by: dayzman | last post by:
Hi, I'm interested in projects evolve about extracing semantic structure of HTML documents. What I mean by extracting semantic structure is to analyse HTML doc and outputs a model (perhaps a tree structure) that relates paragraphs to headings/sub headings. It should be a difficult problem, since HTML is a structure language. Does anyone know of any existing research? Cheers,
3
1755
by: dayzman | last post by:
Hi, I've read somewhere that feature-based analysis can be used to extract the semantic structure of HTML documents. By semantic structure, they mean the model of the rendered view a reader sees. Now, my question is, what should such feature-based analysis involve? What exactly is a feature-based analysis? Please help.
135
7527
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
1
1389
by: Scott Abel | last post by:
Tony Self of HyperWrite presents an interesting and informative article entitled "Semantic, Structured Authoring: The Challenge for Technical Writers" that is sure to be of use to many technical writers struggling to find themselves in the changing world of structured XML authoring and content management. Check it out and leave a comment to let us know what you think. http://www.thecontentwrangler.com The Content Wrangler, Inc.
12
4169
by: rshepard | last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding the solution in the docs I have here. Data are assembled for writing to a database table. A representative tuple looks like this: ('eco', "(u'Roads',)", 0.073969887301348305) Pysqlite doesn't like the format of the middle term: pysqlite2.dbapi2.InterfaceError: Error binding parameter 1 - probably
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.