473,403 Members | 2,183 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,403 software developers and data experts.

[] equivalence?

I've got some char arrays declared, some as

char anArray[10] ;

and some as

char aChar ;

Im trying to ensure that all are null terminated, so am using:

anArray[0] = '\0' ;
aChar[0] = '\0' ;

But the second one does not compile - I get the error:

'The array operator must have one operand that is a pointer to
acomplete type and one of integral type'

I thought that aChar[n] was equivalent to (&aChar + n)?

Obviously aChar = '\0' ; works, but is that not equivalent to
aChar[0] = '\0' ;

ta
Jul 22 '05 #1
4 1529

"Paul Williams" <pa***********@lycosmax.co.uk> wrote in message
news:9d**************************@posting.google.c om...
I've got some char arrays declared, some as

char anArray[10] ;

and some as

char aChar ;

Im trying to ensure that all are null terminated, so am using:

anArray[0] = '\0' ;
aChar[0] = '\0' ;

But the second one does not compile - I get the error:

'The array operator must have one operand that is a pointer to
acomplete type and one of integral type'

I thought that aChar[n] was equivalent to (&aChar + n)?
No, it's *(aChar + n)
Obviously aChar = '\0' ; works, but is that not equivalent to
aChar[0] = '\0' ;


Obviously, aChar[0] == *(aChar + 0), aChar is no pointer. Hence the error.
btw, there are array to pointer conversions. The result is a pointer to the
first element of the array.
Hence, anArray[0] == *( anArray + 0), here anArray is &anArray[0].

-Sharad

Jul 22 '05 #2
On 8 Jun 2004 04:46:17 -0700, pa***********@lycosmax.co.uk (Paul
Williams) wrote:
I've got some char arrays declared, some as
char anArray[10] ;
and some as
char aChar ;
This is *not* an array of char. It is just a char. A single
one.
<snip>
Obviously aChar = '\0' ; works,
Yes, because aChar is a char.
but is that not equivalent to
aChar[0] = '\0' ;


As aChar is not an array, you can't write aChar[0].

--
Andre Heinen
My address is "a dot heinen at europeanlink dot com"
Jul 22 '05 #3
Paul Williams wrote:
I've got some char arrays declared, some as

char anArray[10] ;

and some as

char aChar ;
That is not an array.
Im trying to ensure that all are null terminated, so am using:

anArray[0] = '\0' ;
aChar[0] = '\0' ;

But the second one does not compile - I get the error:

'The array operator must have one operand that is a pointer to
acomplete type and one of integral type'

I thought that aChar[n] was equivalent to (&aChar + n)?


No, arr[n] is equivalent to *(arr+n).

In any case aChar is not an array or pointer so you cannot using the
subscript operator on it. Why are you trying to do it this way anyway?
Jul 22 '05 #4
In message <9d**************************@posting.google.com >, Paul
Williams <pa***********@lycosmax.co.uk> writes
I've got some char arrays declared, some as

char anArray[10] ;

and some as

char aChar ;
That's not an array.
Im trying to ensure that all are null terminated, so am using:

anArray[0] = '\0' ;
aChar[0] = '\0' ;

But the second one does not compile - I get the error:

'The array operator must have one operand that is a pointer to
acomplete type and one of integral type'

I thought that aChar[n] was equivalent to (&aChar + n)?
No, because aChar isn't of array type.

An lvalue or rvalue of array type can be converted to a pointer, so
anArray[n] is equivalent to * (&anArray[0] + n). Note the difference
from what you wrote above.

That conversion is only possible for arrays.

Obviously aChar = '\0' ; works, but is that not equivalent to
aChar[0] = '\0' ;


--
Richard Herring
Jul 22 '05 #5

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

Similar topics

2
by: Kelly | last post by:
Hi, I don't have any visual basic background so pls be patient with me. What the newline \n equivalence in visual basic script? Thanks.
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
10
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of...
26
by: Bj?rn | last post by:
I'm trying to convert some small piece of c++ code to c, only to ease linking it to a third language (I'm not knowledgeable in either c or c++). What would be the the c equivalence of:...
7
by: ben | last post by:
hello, an algorithm book i'm reading talks about the connectivity problem/algorithm. it gives a number of examples where the connectivity problem applies to real life situations (like, the...
2
by: ozbear | last post by:
In C# is there a way to alias or equivalence one type to another? For example, in Delphi, I can say... type TMyFloat = type double; and then cheerfully use TMyFloat in my field definitions,...
1
by: Kenneth P | last post by:
Hi, I'm trying to do some Custom Paging technique with the datagrid object and with the select command in Sql, thus forcing the server to only select those rows from the database that should be...
4
by: Kira Yamato | last post by:
I apologize if this is an off topic question, but I am not sure where is the right forum to ask this: I was wondering what are the currently popular choices for database connectivity in C++. ...
20
by: =?Utf-8?B?ZW1pdG9qbGV5ZXM=?= | last post by:
Hi everyone: i read from the documentation of a dll that there is a struct that uses char for storing an IP address. How can it be? and how come i can get to representate the same value in a...
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...
0
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...

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.