473,595 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are they equivalent ?

Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :

*((char **)v)++ == *((char **)v++)

Where v is a pointer to an array of characters,defi ned as
char *v[];

I am passing "v" to a function expecting a char * .

Apologize for not being able to provide a minimum compilable program.

Tx
~
Dec 13 '05 #1
14 2531
grid wrote:

Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :

*((char **)v)++ == *((char **)v++)

[...]

No, they are not similar.

*((char **)v)++

Dereferences v and post-increments what it points to.

*((char **)v++)

Post-increments v itself, and then dereferences it.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Dec 13 '05 #2


Kenneth Brody wrote On 12/13/05 10:46,:
grid wrote:
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :

*((char **)v)++ == *((char **)v++)
[...]

No, they are not similar.


Right so far.
*((char **)v)++

Dereferences v and post-increments what it points to.
No; this one's a constraint violation. Syntactically,
it asks for the value of `v' to be converted to type `char**',
then for that value to be post-incremented, meanwhile
dereferencing the non-incremented value. The constraint
violation is the attempt to post-increment the expression
`((char**)v)', which is not an lvalue.
*((char **)v++)

Post-increments v itself, and then dereferences it.


Right. Note that the "it" refers to the converted
value of `v' as it was before being incremented.

--
Er*********@sun .com

Dec 13 '05 #3
grid wrote:
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :

*((char **)v)++ == *((char **)v++)

Where v is a pointer to an array of characters,defi ned as
char *v[];


These expressions are not equivalent, and if 'v' is truly an array type (as
opposed to a char**) they are both illegal.

"*((char **)v)++" casts 'v', postincrements it and dereferences it, which is
illegal because the operand of the increment operator may not be a cast
expression (it's not an lvalue).

"*((char **)v++)" postincrements 'v', casts it and dereferences it, which is
illegal because the operand of the increment operator may not be of array
type. This will work if 'v' is a char**, however, in particular if it's a
function argument declared as "char *v[]". But in this case the cast is
superfluous, and the statement as a whole is equivalent to simply "*v++"
(dereferencing and postincrement have the same precedence, and associate
right-to-left).

It's unclear what expression you're going for. You might also mean "v[0]++",
which is equivalent to "(*(char **)v)++" (or simply "(*v)++").

S.
Dec 13 '05 #4
Skarmander wrote:
grid wrote:
Hi,
I have a certain situation where a particular piece of code works on
a particular compiler but fails on another proprietary compiler.It
seems to have been fixed but I just want to confirm if both statements
are similar :

*((char **)v)++ == *((char **)v++)

Where v is a pointer to an array of characters,defi ned as
char *v[];

<snip> It's unclear what expression you're going for. You might also mean
"v[0]++", which is equivalent to "(*(char **)v)++" (or simply "(*v)++").


Note that this only applies if 'v' is really an array of *pointers* to
characters, as your declaration implies. I carelessly glossed over your
assertion that 'v' is a *pointer to an array*. Then the declaration is
wrong: it should be "char (*v)[]", mind the parentheses.

Needless to say, this changes everything... You should be able to work out
the meaning of the expressions and determine what exactly it is you're going
for with the information I provided in the previous post, though.

S.
Dec 13 '05 #5
*((char **)v)++

Dereferences v and post-increments what it points to.


No; this one's a constraint violation. Syntactically,
it asks for the value of `v' to be converted to type `char**',
then for that value to be post-incremented, meanwhile
dereferencin g the non-incremented value. The constraint
violation is the attempt to post-increment the expression
`((char**)v) ', which is not an lvalue.

This is code which I dont have any control over.It was initially used as
simply "*v++".
But later due to some cleanup and to supress lint warnings changed to
the above.Does the increment operator work this way :
*((char **)v) = *((char **)v) + 1
So that the lvalue cast is a constraint violation.
I do get the following errors in the proprietary compiler for which I
have been to forced to change the code :
Warning : Cast is not lvalue; ++ requires lvalue.
Error : Modifiable lvalue required with operator "++".

'v' is as I mentioned earlier a array of pointers to char (an array of
strings) ,
char *v[] ;
And the code moves over these strings one by one passing each string to
a function ( which expects a char *).Since here we have an array of char
pointers, I am getting the error on non-modifiable lvalue since an array
address is a constant.But then that was the reason for the cast to char
**,to make it increment the pointer over the char *'s.
*((char **)v++)

Post-increments v itself, and then dereferences it.


Right. Note that the "it" refers to the converted
value of `v' as it was before being incremented.

I tried it like this to circumvert the errors,but seem to have got the
logic wrong.Since this increments 'v' prior to the dereferencing,I would
be missing the first string that gets passed to the fucntion because I
will get the strings from the second string onwards.
Ofcourse dereferencing and incrementing 'v' without the cast should work
fine (*v++), but the first statement seems to work on a particular
platform.If this is a constraint violation it should be caught on both
the compilers.

Thanks for all the insights.
Appreciate your comments.
TIA
~
Dec 13 '05 #6


grid wrote On 12/13/05 13:30,:
*((char **)v)++

Dereferences v and post-increments what it points to.
No; this one's a constraint violation. Syntactically,
it asks for the value of `v' to be converted to type `char**',
then for that value to be post-incremented, meanwhile
dereferenci ng the non-incremented value. The constraint
violation is the attempt to post-increment the expression
`((char**)v)' , which is not an lvalue.


This is code which I dont have any control over.


Does that mean you cannot change it? The code is
incorrect C; if you can't change it, you can't fix it.
It was initially used as
simply "*v++".
But later due to some cleanup and to supress lint warnings changed to
the above.Does the increment operator work this way :
*((char **)v) = *((char **)v) + 1
So that the lvalue cast is a constraint violation.
It's just like `int x; (double)x = 3.14159;' or
like `(2 + 2)++' or like `printf("hello\ n") = 42;'.
You cannot assign new values to such things.
I do get the following errors in the proprietary compiler for which I
have been to forced to change the code :
Warning : Cast is not lvalue; ++ requires lvalue.
Error : Modifiable lvalue required with operator "++".
The proprietary compiler is correct. But "forced to
change?" I thought you said you have no control over
this code ...
'v' is as I mentioned earlier a array of pointers to char (an array of
strings) ,
char *v[] ;
As it stands and in isolation, this declaration of
`v' is incorrect and requires a diagnostic. Please
provide the rest of the context.
And the code moves over these strings one by one passing each string to
a function ( which expects a char *).Since here we have an array of char
pointers, I am getting the error on non-modifiable lvalue since an array
address is a constant.But then that was the reason for the cast to char
**,to make it increment the pointer over the char *'s.

*((char **)v++)

Post-increments v itself, and then dereferences it.
Right. Note that the "it" refers to the converted
value of `v' as it was before being incremented.


I tried it like this to circumvert the errors,but seem to have got the
logic wrong.Since this increments 'v' prior to the dereferencing,I would
be missing the first string that gets passed to the fucntion because I
will get the strings from the second string onwards.


You do not understand the post-increment operator (and
probably don't understand post-decrement, either.) Go back
to your C textbook. Snap quiz: assuming appropriate headers
and other context, what is the output of

int x = 1;
printf ("%d\n", x++);
printf ("%d\n", x);
Ofcourse dereferencing and incrementing 'v' without the cast should work
fine (*v++), but the first statement seems to work on a particular
platform.If this is a constraint violation it should be caught on both
the compilers.


Some popular compilers are not really compilers for C
but for a C-ish language with some extra decorations the
compiler writers thought would look festive. I strongly
suspect you're using gcc, in which case you might find it
instructive to tell it to shed its garish decor and dress
more soberly: "gcc -W -Wall -ansi -pedantic ..." will get
it to behave better.

--
Er*********@sun .com

Dec 13 '05 #7
On 2005-12-13, Kenneth Brody <ke******@spamc op.net> wrote:
grid wrote:

Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :

*((char **)v)++ == *((char **)v++)

[...]

No, they are not similar.

*((char **)v)++

Dereferences v and post-increments what it points to.

*((char **)v++)

Post-increments v itself, and then dereferences it.


wrong - if there's a difference, it's in whether the increment applies
to the cast version of v [which is not standard C, cast results are not
lvalues] or to the original.

*x++ === *(x++)
Dec 13 '05 #8
Eric Sosman wrote:
grid wrote On 12/13/05 13:30,:
char *v[] ;


As it stands and in isolation, this declaration of
`v' is incorrect and requires a diagnostic. Please
provide the rest of the context.


Conceivably the code was:

foo(v)
char *v[];
{
...
}

which would explain why the original code successfully
modified v, and why some compilers had trouble with it.

Also, char *v[]; in isolation could be a tentative definition
(but that is unlikely given the rest of the OP's message).

Dec 13 '05 #9


Old Wolf wrote On 12/13/05 17:02,:
Eric Sosman wrote:

grid wrote On 12/13/05 13:30,:
char *v[] ;
As it stands and in isolation, this declaration of
`v' is incorrect and requires a diagnostic. Please
provide the rest of the context.

Conceivably the code was:

foo(v)
char *v[];
{
...
}


Aha! You're right -- it's been so many years since
I wrote a prototypeless function definition that I'd all
but forgotten they existed.
which would explain why the original code successfully
modified v, and why some compilers had trouble with it.

Also, char *v[]; in isolation could be a tentative definition
(but that is unlikely given the rest of the OP's message).


Yes, the tentative definition angle was one of the
possibilities I thought of, and one reason I asked for
the rest of the context. Another possiblity was that
the code actually said `extern char *v[];'. And the
third, which I thought most likely, was that the context
looked like `foo(char *v[]) { ... }' and that the
semicolon had been tacked on by a reflexive error. But
now I think it more likely that he's really got an old-
style function definition, fifteen years out of date.

Anyhow, once the O.P. provides the context we'll
know for sure, and maybe be able to fix his problem.

--
Er*********@sun .com

Dec 13 '05 #10

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

Similar topics

14
7257
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server running. I prefer not to. I just need Python components for local consumption in other languages. I remember Gnome libs having some thing like this. Any thoughts?
2
3273
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. Javascritp has >>> and >>. >>> is a zero fill bit shift whereas >> is a sign propagating bit shift. My understanding is that the python >> is equivalent to the javascript >> - but python has no equivalent to >>>. Would a >>> 3 in javascript be...
3
2287
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an ordinary Lisp S-expression. So it's easy enough to translate some XML into equivalent Lisp. Now I turn it over to the Lisp parser, which creates the equivalent of the DOM for me.
1
3781
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different presentation styles and different data sources. Presentation styles like tabular format , graph format, grid format, freeform format, Composite format(somthing
6
5158
by: Frank Rachel | last post by:
So I can focus on the correct areas of research, I was wondering if someone could give me the .NET equivelents for this J2EE architecture: JSP's make calls to local JavaBean Controls. The controls do a JNDI lookup to invoke methods on EJB's. The EJB's use local Java classes, and these classes use JDBC to do database work. Example: Login.jsp contains "import xxx.LoginControl", and invokes the "login"
3
3143
by: Marty | last post by:
Hi, What is the VB.NET equivalent of the VB6 ADODB.Connector and ADODB.Recordset? Thanks Marty
7
3720
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s : String;
10
7316
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
4034
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric equivalent. Is there such a function available in C#? I can see that VB.NET has one, but I couldn't see how to get at it in C#. For example, if I have ...
0
7957
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, 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...
0
7883
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,...
1
8020
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
8252
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 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...
0
6675
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 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...
0
5421
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
3875
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...
0
3915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1491
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.