473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why Warning?

Hi all,
My compiler is warning for passing a two dimensional character array to
a function which accepts "char**" as parameter.Can u please shed some
light on this issue?How can I get rid of this warning?
I am using Visual C for compiling.
Thanks

Nov 14 '05 #1
4 1117
va******@rediffmail.com wrote:

Hi all,
My compiler is warning for passing a two dimensional character array to
a function which accepts "char**" as parameter.Can u please shed some
light on this issue?
We'll need some code to explain this, so let's write some.

#define M 10
#define N 12

void foo(char **);

int main(void)
{
char Names[M][N];
foo(Names); /* here's the problem - but why? see below */
return 0;
}

In C, a[i] is equivalent to *(a + i), by definition.
Therefore, &a[i] is equivalent to &*(a + i).
&* cancel, so &a[i] is equivalent to (a + i).
Let i = 0.
So &a[0] is equivalent to (a + 0), and (a + 0) is just a.

In a value context (such as a function call), then, the name
of an array is interpreted as a pointer to the first element
of that array.

Names[0] is an array of N char.

So &Names[0] is a pointer to an array of N char. That is,
it has the type char (*)[N]. This is not the same type as
char **, which is "pointer to pointer to char" rather than
"pointer to array of N char".
How can I get rid of this warning?


One way would be to change the parameter type to char (*)[N].
If that isn't acceptable, you could re-design your array to be
an array of pointers to char, using dynamic allocation to get
the memory for the strings if need be.
Nov 14 '05 #2
In article <11*********************@o13g2000cwo.googlegroups. com>,
va******@rediffmail.com wrote:
Hi all,
My compiler is warning for passing a two dimensional character array to
a function which accepts "char**" as parameter.Can u please shed some
light on this issue?How can I get rid of this warning?
I am using Visual C for compiling.


You should get a proper compiler that produces an error instead of a
warning. That is a problem with Visual C; it often allows you to compile
completely broken code and only gives a warning.

char** is a pointer to an array of pointers. A two dimensional array is
not an array of pointers, it is an array of arrays. So either the design
of the function interface is completely wrong, or you using it in a
completely wrong way.
Nov 14 '05 #3
On Tue, 22 Feb 2005 00:44:20 +0000, Christian Bau
<ch***********@cbau.freeserve.co.uk> wrote in comp.lang.c:
In article <11*********************@o13g2000cwo.googlegroups. com>,
va******@rediffmail.com wrote:
Hi all,
My compiler is warning for passing a two dimensional character array to
a function which accepts "char**" as parameter.Can u please shed some
light on this issue?How can I get rid of this warning?
I am using Visual C for compiling.
You should get a proper compiler that produces an error instead of a
warning. That is a problem with Visual C; it often allows you to compile
completely broken code and only gives a warning.


The C standard does not define "error" or "warning". It only
specifies "diagnostics" that are required in cases of syntax error or
constraint violation.
char** is a pointer to an array of pointers. A two dimensional array is
not an array of pointers, it is an array of arrays. So either the design
of the function interface is completely wrong, or you using it in a
completely wrong way.


This paragraph of your reply is completely true, but it is your first
paragraph that is broken, not "proper". The C standard that Microsoft
compilers adhere to NEVER forbids a translator to produce an
executable, no matter what is wrong with the source.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
In message <qq********************************@4ax.com>
Jack Klein <ja*******@spamcop.net> wrote:
On Tue, 22 Feb 2005 00:44:20 +0000, Christian Bau
<ch***********@cbau.freeserve.co.uk> wrote in comp.lang.c:
You should get a proper compiler that produces an error instead of a
warning. That is a problem with Visual C; it often allows you to compile
completely broken code and only gives a warning.


The C standard does not define "error" or "warning". It only
specifies "diagnostics" that are required in cases of syntax error or
constraint violation.


Yes, we know, but it's a quality of implementation thing, isn't it? If a
compiler doesn't distinguish between a blatantly incorrect piece of code that
violates an ISO constraint and something it thinks is just a little bit iffy,
how on earth is the average programmer supposed to know whether a "warning"
is important?

The last thing people who regard the C standard as important should be doing
is leaping to the defence of implementations like this, just to score a few
pedant points.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 14 '05 #5

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

Similar topics

3
by: Bas Wassink | last post by:
Hello there, I'm having trouble understanding a warning produced by 'splint', a code-checker. The warning produced is: keywords.c: (in function keyw_get_string) keywords.c:60:31: Released...
3
by: Bill Burris | last post by:
How do I find what is causing this warning from the Linker? If I use /NODEFAULTLIB I get hundreds of undefined symbols. LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other...
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
5
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
1
by: Ian | last post by:
I've just discovered the msclr::lock class in the C++ Support Library online documentation. This seems like a much cleaner way to implement thread protection than using...
5
by: holmescn | last post by:
what is the meaning of warning attributes ignored on template instantiation. i got it when i compiled stlport 5.1.3. anybody can help me ? thx!
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
4
by: cody | last post by:
It is possible to declare and use/instantiate a class with a uninitialized readonly field without even a compiler warning. Why don't I get warnings? public class Stuff { public readonly int a;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.