N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary &
operator, or is a string literal used to initialize an array, an
expression that has type ''array of type'' is converted to an
expression with type ''pointer to type'' that points to the
initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */
char (*arr_ptr)[10]; /* (line 2) */
arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on
compilation I get the following errors.
1) In this statement, & before array "arr" is ignored.
2) In this statement, the referenced type of the pointer
value "&arr" is "signed char", which is not compatible
with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr
both have the same types. 13 1346 ju**********@ya hoo.co.in wrote: N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types.
Are you using a pre-ansi C compiler? Such compilers might generate
these types of warnings, see FAQ 6.12.
Robert Gamble ju**********@ya hoo.co.in wrote: N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types.
Your code is perfectly legal. You must have been using a broken
compiler.
Krishanu ju**********@ya hoo.co.in wrote: N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types.
What's your compiler?
I got nothing under DEV-C++.
and, &arr has the same value with arr,run this program
#include <stdio.h>
int main(void)
{
char arr[6] = "hello";
printf("arr = %d", arr);
printf("&arr = %d", &arr);
return 0;
}
<ju**********@y ahoo.co.in> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com... Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types.
Based on the warning message, I assume you are using
the DEC/Compaq/HP Ccompiler on Tru64 or OpenVMS.
If this is not correct...ignor e the rest of this reply.
You are getting these messages because you are invoking
the compiler in its "K & R" mode. Some early C compilers
ignored the & operator when it was used on an array.
You specified K & R mode by either using the -std0
switch, or you are using a very old version of the compiler
where -std0 was the default behavior.
If you specify -std, the compiler will use it's "Relaxed" Standard
mode, and should compile the program as you expect.
Ed Vogel
HP/Compaq/DEC C/C++ Engineering ju**********@ya hoo.co.in writes: N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types.
First of all, I don't think the message '& before array "arr" is
ignored' is an error message; it looks more like a warning.
Was that the actual code you compiled? The error message refers to
"signed char", but all your declarations use plain "char". (Possibly
a compiler might (incorrectly) treat char and signed char as the same
type.) And it refers to "array [3] of signed char"; I don't see a
3-element array of *anything* in your code fragment.
You know the drill. Post the *exact* code you compiled (cut-and-paste
the entire small compilable program) and the *exact* messages you got
from the compiler (cut-and-paste again). Otherwise, we can't guess
which errors are in your original code and which were introduced when
you re-typed it.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... Was that the actual code you compiled? The error message refers to "signed char", but all your declarations use plain "char". (Possibly a compiler might (incorrectly) treat char and signed char as the same type.) erefore, we must do this.
Unless that compiler was told to compile the program in K & R mode
(where "char" and "signed char" could be treated the same as there
was no "signed char" in K & R C) as I speculated in an earlier reply.
Ed Vogel
HP/Compaq/DEC C/C++ Engineering.
"Ed Vogel" <ed************ ************@hp .com> writes: "Keith Thompson" <ks***@mib.or g> wrote in message news:ln******** ****@nuthaus.mi b.org... Was that the actual code you compiled? The error message refers to "signed char", but all your declarations use plain "char". (Possibly a compiler might (incorrectly) treat char and signed char as the same type.) erefore, we must do this.
Unless that compiler was told to compile the program in K & R mode (where "char" and "signed char" could be treated the same as there was no "signed char" in K & R C) as I speculated in an earlier reply.
You're right, the compiler does refer to "signed char" when I invoke
it with "cc -std0" (K&R mode) -- but it still doesn't refer to a
3-element array when the source declares a 10-element array.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... You're right, the compiler does refer to "signed char" when I invoke it with "cc -std0" (K&R mode) -- but it still doesn't refer to a 3-element array when the source declares a 10-element array.
Keith,
When I try the program here, the message refers to a 10 element
array. As you pointed out, we need the real code posted.
Thanks!
Ed
On 9 Aug 2005 05:43:56 -0700, ke******@hotmai l.com wrote in
comp.lang.c: ju**********@ya hoo.co.in wrote: N869, Page 47,
"Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object and is not an lvalue."
Now, consider following piece of code,
char arr[10]; /* (line 1) */ char (*arr_ptr)[10]; /* (line 2) */ arr_ptr = &arr; /* (line 3) */
&arr should have type, pointer to array of 10 chars. But, on compilation I get the following errors.
1) In this statement, & before array "arr" is ignored. 2) In this statement, the referenced type of the pointer value "&arr" is "signed char", which is not compatible with "array [3] of signed char".
Why "line 3" is giving the above warnings ? arr_ptr and &arr both have the same types. What's your compiler? I got nothing under DEV-C++. and, &arr has the same value with arr,run this program
No, don't tell anyone to run your program. It contains too many
instances of undefined behavior.
#include <stdio.h>
int main(void) { char arr[6] = "hello";
printf("arr = %d", arr);
A conversion specifier of "%d" requires an argument of signed int.
Passing it a pointer to char produces undefined behavior.
printf("&arr = %d", &arr);
A conversion specifier of "%d" requires an argument of signed int.
Passing it a pointer to an array of 6 chars produces undefined
behavior.
return 0; }
Now let's fix your program to make it legal, defined, valid C:
#include <stdio.h>
int main(void)
{
char arr[6] = "hello";
printf("arr = %p", arr);
printf("&arr = %p", (void *)&arr);
return 0;
}
Note the use of the "%p" conversion specifier, which is defined for an
argument of type pointer to void. In the cast of 'arr', which is
converted to a pointer to char in this usage, no cast is necessary
because pointer to any of the character types has the same
representation and is passed to functions identically as pointer to
void. The cast is necessary when passing '&arr', which has the type
"pointer to array of six characters".
Note also that, converted to the same type, 'arr' and '&arr' will
contain the same address, but do not have the same type.
--
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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alf P. Steinbach |
last post by:
// As usual the error message directs one to the report the bug.
//
// And as usual there is absolutely no way to do so without paying for
// the privilege...
//
// Or using three or four hours to find the _current_ reporting page...
#include <vector>
#include <iostream>
|
by: Adrian |
last post by:
Hi all,
I am getting a warning compiling the following code using Borland C++
Builder 6, but I dont think I am doing anything wrong. When using g++ I
get no warnings at all with a g++ -Wall -ansi -pedantic.
Now I usually assume the compiler is correct but in this case I am not sure.
push 1 gives the warning the other 2 go through fine.
|
by: Markus Sandheide |
last post by:
Hello!
Execute these lines:
int x = 1;
x = x > 2345678901;
You will get:
x == 1 with Borland C++ Builder
|
by: junky_fellow |
last post by:
Consider the following piece of code:
struct junk {
int i_val;
int i_val1;
char c_val;
};
int main(void)
{
|
by: Ondrej Spanel |
last post by:
I though that inline functions should be always visible only in the
compilation unit where they are defined - meaning if compiler cannot inline
them, they should be handled as if declared static. However sample attached
shows VC compiler does not work this way (tested in .NET 2003). When you
compile the sample with inlining enabled (like in default Release config),
the output is A1 = 1, A2 = 2. When run with inlining disabled (Debug),...
| |
by: Alan Cobb |
last post by:
Hi,
In the managed C++ class below I get compile warning C4677
from VS2003. "signature of non-private function contains
assembly private type", even though the managed enum is
public. I have to drop the "enum" keyword from my member
variable declaration to keep the compiler happy.
Shouldn't I technically be able to use the "enum" keyword
without a warning?
|
by: cyber citizen |
last post by:
Hi Folks,
We are encountering the following code issue on compiler susch as "xlc","gcc" but "icc" passes it successfully.
Sample code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;
|
by: zeppe |
last post by:
Hi all,
I've a problem. The code that follows creates a warning in both gcc and
visual c++. However, I think it's correct: basically, there is a
function that return an object of a derived class, that's bounded to a
base class reference to delay the destruction of the actual object to
the end of the reference scope. Actually, I don't use the reference: the
code that matters is in the destructor, and I want it to be executed at
the end...
|
by: Ajinkya |
last post by:
Can anyone suggest me a good compiler for(c/cpp) for windows?
I tried dev cpp but its debugging facility is very poor.
|
by: Chris Peters |
last post by:
Hi,
I'm using some Fortran 77 code together with C, and the compiler is giving
me some strange warnings. Can anyone help explain what's going on? The
code runs just fine.
1)
Fortran code
|
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 project—planning, coding, testing, and deployment—without 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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |