In a .Net application, given a C++ dll with methods called by a C# GUI
Assume (x&y) is FALS
the following code in the C++ dll, when called from the C# interface
bool theMethod(unsig ned int x)
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
return true
els
return false
1. Does NOT print the text "True
2. Does return TRU
While the following code
theMethod(unsig ned int x
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
printf("")
return true
els
printf("")
return false
1. Does NOT print the text "True
2. Does return FALS
Question
Why is this happening? 9 1368
Correction to the code fragment
Bothe versions of "theMethod" return "bool
bool theMethod(unsig ned int x
...
----- Honus wrote: ----
In a .Net application, given a C++ dll with methods called by a C# GUI
Assume (x&y) is FALS
the following code in the C++ dll, when called from the C# interface
bool theMethod(unsig ned int x)
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
return true
els
return false
1. Does NOT print the text "True
2. Does return TRU
While the following code
bool theMethod(unsig ned int x
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
printf("")
return true
els
printf("")
return false
1. Does NOT print the text "True
2. Does return FALS
Question
Why is this happening?
Correction to the code fragment
Bothe versions of "theMethod" return "bool
bool theMethod(unsig ned int x
...
----- Honus wrote: ----
In a .Net application, given a C++ dll with methods called by a C# GUI
Assume (x&y) is FALS
the following code in the C++ dll, when called from the C# interface
bool theMethod(unsig ned int x)
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
return true
els
return false
1. Does NOT print the text "True
2. Does return TRU
While the following code
bool theMethod(unsig ned int x
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
printf("")
return true
els
printf("")
return false
1. Does NOT print the text "True
2. Does return FALS
Question
Why is this happening?
> if (x&y)
Since I work in VB, I may not be best person to suggest this
but shouldn't there be two ampersands (&&)?
--
Pozdrav,
Josip Medved, MCSD http://www.jmedved.com
Josip Medved <jm*****@jmedve d.com> wrote: if (x&y)
Since I work in VB, I may not be best person to suggest this but shouldn't there be two ampersands (&&)?
No - x&y does a bitwise AND operation.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> > Since I work in VB, I may not be best person to suggest this but shouldn't there be two ampersands (&&)?
No - x&y does a bitwise AND operation.
true.
but from source code it seems to me that he is trying to perform
logical AND operation since he is checking for true and false.
--
Pozdrav,
Josip Medved, MCSD http://www.jmedved.com
Josip Medved <jm*****@jmedve d.com> wrote: Since I work in VB, I may not be best person to suggest this but shouldn't there be two ampersands (&&)?
No - x&y does a bitwise AND operation.
true. but from source code it seems to me that he is trying to perform logical AND operation since he is checking for true and false.
In C/C++, any non-zero value is regarded as true. So basically,
if (x&y)
evaluates to true if both x and y are non-zero.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Jon
How about when x = 1 and y = 2? The bitwise AND of these is zero, so surely
the statement should evaluate to false.
Also, pre-empting a reply by the OP, I took it that his issue is the
apparent inconsistency of the result, not that it evaluates to one true or
false for given values of x and y.
Charles
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Josip Medved <jm*****@jmedve d.com> wrote: > Since I work in VB, I may not be best person to suggest this > but shouldn't there be two ampersands (&&)?
No - x&y does a bitwise AND operation.
true. but from source code it seems to me that he is trying to perform logical AND operation since he is checking for true and false.
In C/C++, any non-zero value is regarded as true. So basically,
if (x&y)
evaluates to true if both x and y are non-zero.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Charles Law <bl***@nowhere. com> wrote: How about when x = 1 and y = 2? The bitwise AND of these is zero, so surely the statement should evaluate to false.
Apologies - yes, indeed it should. I'm half asleep :)
Also, pre-empting a reply by the OP, I took it that his issue is the apparent inconsistency of the result, not that it evaluates to one true or false for given values of x and y.
Indeed.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Howdy
For some reason, after my initial posting of this query, I was unable to see it (or any responses). In the code example cited, the values of the unsigned ints will always be either 1 or 0. So the test works by returning true if either value is set to 1. There is no condition where a value will be equal to 2
However, as noted, the basic issue I have is: Why is the return value (at least as interpreted by the calling, C# method), dependent upon a bogus printf statement, rather than what the statement actually evaluates to
No one seems to have an answer to that question, and quite frankly, it makes me quite skeptical of the entire development environment (not that it takes much to arouse my skepticism where Microsoft is concerned)
----- Jon Skeet [C# MVP] wrote: ----
Charles Law <bl***@nowhere. com> wrote How about when x = 1 and y = 2? The bitwise AND of these is zero, so surel the statement should evaluate to false
Apologies - yes, indeed it should. I'm half asleep :
Also, pre-empting a reply by the OP, I took it that his issue is th apparent inconsistency of the result, not that it evaluates to one true o false for given values of x and y
Indeed
--
Jon Skeet - <sk***@pobox.co m http://www.pobox.com/~skee
If replying to the group, please do not mail me to This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Privacy Trap |
last post by:
Hi I have a slight problem in trying to set up 2 forms linked to
tables.
What I want to do is to inform a control on one form(Apps)
as to the value of a key of a 'new' record entered via a
second(Clients)
In opening the second form I set up certian fields and controls
on it from the first. In doing so however this seemingly creates a...
|
by: Not Available |
last post by:
On the host server:
namespace JCart.Common
public class JCartConfiguration : IConfigurationSectionHandler
private static String dbConnectionString;
public static String ConnectionString
{
get
{
return dbConnectionString;
|
by: Alex |
last post by:
my app was working fine in VB.NET 2003 (and framework 1.1). Now with
VB.NET 2005 (framework 2.0) the uploading to an http server (ie.
www.sharebigfile.com) stops with the error "The request was aborted:
The request was canceled" after about 7 MB.
For example, I might be uploading a 73MB file. After about 11% done the
upload aborts. :shake:...
|
by: ssg31415926 |
last post by:
I need to compare two string arrays defined as string such that the
two arrays are equal if the contents of the two are the same, where
order doesn't matter and every element must be unique.
E.g. these two arrays would test as equal:
servers = "Admin"
servers = "Finance"
servers = "Payroll"
servers = "Sales"
|
by: Mike Baugh |
last post by:
I am using visual studio 2005 to develop a form using c#
I have 3 datagrids on one form.
I can set the row color based on a certain value in a column. However this
color applies to all 3 datagrida. I would like to set it so that
if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green
if value of column 3 in...
| |
by: DJG79 |
last post by:
Hi all,
I am using an open source menu that i found and it works great, except
for one thing that when the web page is not scrolled to the very top
the drop down links will not stay visible. Has anyone else had this
sort of problem with javascript? and any ideas how to fix it would be
greatly appreciated..
I have included a copy of the...
|
by: boyleyc |
last post by:
Hi all
the following code works perfectly well. Basically it populates a
series of check boxes on my form, depending on whether dlookup finds an
associated record.
The problem i have is that when the date (or xDate) goes over to the
next month, dlookup returns NULL even though though there is a record.
For example if CALWEEKSTART is...
|
by: sewid |
last post by:
Hi there!
I've got a problem with no solution, I hope you might help me.
I am writing a small tool with many buttons. Every button starts a
thread and this thread starts something else, in the example posted
below, the hardware configuration dialog. My problem is, that
sometimes when I close the executed program / application / dialog, my...
|
by: defn noob |
last post by:
isPrime works when just calling a nbr but not when iterating on a
list, why? adding x=1 makes it work though but why do I have to add
it?
Is there a cleaner way to do it?
def isPrime(nbr):
for x in range(2, nbr + 1):
if nbr % x == 0:
break
|
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...
|
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...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
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...
|
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.
| |