473,796 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set and reset the least significant bit of a address

I want to set and reset the least significant bit of a address (where a
pointers points to).
I tried this, but it is not correct:
#define BIT 0x1

void foo(){
void *p;
*p = *p & ~BIT
}
Nov 14 '05
52 7076
jacob navia wrote:
Peter Nilsson wrote:
The conversion to and from intptr_t is implementation defined.
This method may well fail to do what's expected on some (real)
machines.

The C standard says (page 256)
<<
The following type designates a signed integer type with the
property that any valid pointer to void can be converted to
this type, then converted back to pointer to void,
and the result will compare equal to the original pointer:

intptr_t

<<

1) It is *not* optional.
2) If it fails to do what is specified this is a broken
implementation.


Has this changed from N869 then, which goes on to say "These types are
optional." ?
The current C standard is C99. Of course there are people
that want to destroy C and make it go back to 1969
when it didn't exist. I hope you are not one of them.
Wanting people to know that almost all compilers do not support the
latest standard is not the same as wanting the language to die.
What I fail to understand are the people that always
speak about "Standard C" but they mean some inexistent
standard. The C89 Standard doesn't exist any more.

It was replaced by the current one.


Unless someone has gone around deleting all copies of the old standard
it still exists. It just is not the official current standard, only the
standard that actually is implemented.

Since, as you have been told before, we deal with portable C it is
important to know which version of the standard is applicable when it is
not the most commonly implemented one.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #11
Christian Bau wrote:
2) If it fails to do what is specified this is a broken
implementation.

Apparently not.


Very easy.

Just say

"apparently not".

Not that you would bother to give any
ARGUMENTS why intptr_t would be OK when not doing what
it should do or in which machine/implementation that
doesn't work.

Maybe in a ternary machine using 45.87bits per byte
where sizeof char is 7.9 that would not work isn't it?
Nov 14 '05 #12
Flash Gordon wrote:
Unless someone has gone around deleting all copies of the old standard
it still exists. It just is not the official current standard, only the
standard that actually is implemented.

Of course you and the old standard exist.
I wouldn't discuss that.

But "standard C" then, makes no sense.

You want YOUR particular view of the standard, as you would like
it to be.

When implementing the extensions of lcc-win32 I cared to
remain compatible with the standard. But when I discuss them
a holy alliance of people like you start crying

"Standard C, Standard C"

Now, the same people write:

The standard is what I want it to be. I will use this
standard, that standard, etc.

Since, as you have been told before, we deal with portable C it is
important to know which version of the standard is applicable when it is
not the most commonly implemented one.


Ahh not standard C but portable C.

OK. Then how would you implement portably

<inttype> p = (void *)p;

?????????
Nov 14 '05 #13
Richard Tobin wrote:
In article <42************ *********@news. wanadoo.fr>,
jacob navia <ja***@jacob.re mcomp.fr> wrote:
What I fail to understand are the people that always
speak about "Standard C" but they mean some inexistent
standard. The C89 Standard doesn't exist any more.

Standards are for our benefit, not the standards bodies'. If we
continue to use C89, it still exists.


Of course. It is not standard C though.

It is obsolete C.

But you are free to use it. Microsoft Corp has the same
view.
Nov 14 '05 #14
Walter Roberson wrote:
In article <42************ *********@news. wanadoo.fr>,
jacob navia <ja***@jacob.re mcomp.fr> wrote:
:The current C standard is C99. Of course there are people
:that want to destroy C and make it go back to 1969
:when it didn't exist. I hope you are not one of them.

:What I fail to understand are the people that always
:speak about "Standard C" but they mean some inexistent
:standard. The C89 Standard doesn't exist any more.

:It was replaced by the current one.

Tell me, did your house / apartment stop existing when they
last revised the relevant Construction Code [e.g., required
that certain kinds of nails be 1mm thicker] ?


If the construction code changed the standards for nails
and my appartment has the old nails, my appartment is then
NOT STANDARD, and when I sell it, or for the insurance claims
I am supposed to change the nails.

Of course I can go on living in my house without bothering about
standards. Only if I got a problem, the insurance could argue that
I was using a non-standard nail size and if my roof collapses
that is not covered by their contract.

Nov 14 '05 #15
Keith Thompson wrote:
You're complaining about someone mentioning that intptr_t is specific
to C99. Would you prefer that we post answers that assume everyone
has a C99 compiler, so they can come back and ask us what's wrong when
it doesn't work with their C90 compilers?


You are to a certain point right. I should have mentioned this in my answer.

What I fail to understand are the vague suppositions like:

"It may not work in some machines", without any qualifiers.

Besides, this stuff starts to become a self-fullfiling
prophecy. If everyone says the C99 standard is dead, it may
very well be.

It is implemented in several compilers. You can have under
linux gcc, and under windows you get lcc-win32 or Intel,
as far as I know. So, for many desktops machines this can
be solved. For the embedded systems this is another story.

jacob

Nov 14 '05 #16
jacob navia wrote:
Christian Bau wrote:
2) If it fails to do what is specified this is a broken
implementation.

Apparently not.


Very easy.

Just say

"apparently not".

Not that you would bother to give any
ARGUMENTS why intptr_t would be OK when not doing what
it should do or in which machine/implementation that
doesn't work.


Now, now, let's take a deep breath, and quit being so hostile.
*Apparently* an implementation that does not define intptr_t is *not*
broken.

Thus, "Apparently not". Capische? Is that so terrible?
Maybe in a ternary machine using 45.87bits per byte
where sizeof char is 7.9 that would not work isn't it?


No need to get uppity. Christian's regular and generally accurate
posts are undeserving of your sarcastic disregard.
Mark F. Haigh
mf*****@sbcglob al.net

Nov 14 '05 #17
jacob navia wrote:
Flash Gordon wrote:
Unless someone has gone around deleting all copies of the old standard it still exists. It just is not the official current standard, only the standard that actually is implemented.


Of course you and the old standard exist.
I wouldn't discuss that.

But "standard C" then, makes no sense.


<snip>

Yeah, it does. "Foo" is valid C89. "Bar" is valid C99. What's so
hard to understand about that?

In theory you may be right. In practice, it's nowhere near as
difficult as you make it out to be.
Mark F. Haigh
mf*****@sbcglob al.net

Nov 14 '05 #18
In article <42************ *********@news. wanadoo.fr>,
jacob navia <ja***@jacob.re mcomp.fr> wrote:
:Walter Roberson wrote:
:> Tell me, did your house / apartment stop existing when they
:> last revised the relevant Construction Code

:If the construction code changed the standards for nails
:and my appartment has the old nails, my appartment is then
:NOT STANDARD, and when I sell it, or for the insurance claims
:I am supposed to change the nails.

It isn't uncommon for the Construction Code to change every few months.
National fire code, state/provincial codes, municipal codes, some set
forth in the form of laws and others merely in the form of regulations
that can be changed by a staff member at City Hall.

Except in rare instances, changes in the Construction Code do *not*
require renovations, because most changes are "grandfathe red" --
meaning that they only apply to -new- work done.

Retrofitting is usually only required for serious health threats, such
as asbestos; urea formaldehide foam (and even that stayed legal in
sealed installations); dioxin-filled transformers; or the use of very
thin aluminium wiring.

--
Usenet is like a slice of lemon, wrapped around a large gold brick.
Nov 14 '05 #19
In article <7k************ *************** *****@4ax.com>,
<no*@given.ou t> wrote:
:For example... I would love to see a C implementation (not c++ or C#...
:basic C99) with real string variables. And why not? So long as the
:compiler meets some agreed minimum standard, what's wrong with going beyond
:that?

If one writes a program that requires the extensions, then the program
is only as portable as the compiler is.

If one programs without the extensions, then the extensions were not
needed.

The point of standards is to have a common base, and that any program
that meets the standard (and which takes into account implicit hardware
dependancies such as characters not always being 8 bits) can be used
without change elsewhere, saving the time necessary to adapt, re-write,
and re-test.
--
Walter Roberson is my name,
And Usenet is my nation.
Cyber space is my dwelling pace,
And flames my destination.
Nov 14 '05 #20

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

Similar topics

5
7756
by: Eric Kincl | last post by:
Hey, I was wondering if it's possible to reset the "auto_increment" feature in MySQL. For example, if I have a database with a list that will change every year (the old list be completely flushed out, deleted) and then I insert a new list, it will very quickly reach the max INDEX length... Does it just wrap itself? Is there a way to reset "auto_increment" so that I can flush all the rows, reset auto_increment, and start from scratch? ...
4
11195
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib, this code returns the traceback that follows: import telnetlib host = 'nnn.nnn.nnn.nnn'
16
20534
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number can go without the system crashing. An ancillary question is how one resets an auto number so that the sequence starts again at 1. In the case of this file, the auto number field serves no useful purpose except as an
8
2178
by: spike | last post by:
My prygram goes through a string to find names between '\'-characters The problem is, parts of the name in sTemp remains if the new name is shorter than the old name. code --------------------------------------------------- char sTemp; char sText = "THELONGESTNAME\\samantha\\gregor\\spike\\..."; // and so on...
20
9180
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg., int_fast32_t 4) integer capable of holding a pointer, intptr_t 5) widest integer in the implementation, intmax_t Is there a valid motivation for having both int_least and int_fast?
0
1434
by: Larry Serflaten | last post by:
I recently fired up VS2003 while online which I have done on numerous occasions before. When I opened the toolbox, ZoneAlarm popped up a box saying the IDE wanted to access the internet. This was the first time it tried to connect to the internet, that I can recall, and it was to some address I did not recognise, so I denied it. VS hung, and when I tried to kill the process (Task Manager) all my desktop windows went into tiled view...
3
18750
by: kashif_khan | last post by:
hi everyone, can anybody please tell me why reset button is not working in the following code, i tested it in opera, firefox and konqueror, <form action='edit_links.php' method='POST' name='save_links' id='save_links'> <table cellpadding='5'>
4
7978
by: thegeneralguy | last post by:
Hello, I'm trying to find the least significant set bit (i.e. the first '1' bit in an int) through just bit twiddling, but I can't get it without resorting to a loop. My original idea was to reverse the bits in an int and find the most significant bit then subtract it from 31 to get the position of the LSB. Is there a way to get the LSB of an int using just bit manipulations? e.g., 0b0101 would return 0001, 0b0000 would return...
2
3205
by: DarthPeePee | last post by:
Hello everyone. I am working on a Password Strength Meter and I am running into 1 problem that I would like to fix. When pressing the "Clear Password & Try Again" button, the password clears out of the text box, but the meter will stay at its current position until text is entered back into the textbox. Once text is re-entered, the meter will display the results again. I would like everything to reset when the button is pushed, but I...
0
9685
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
9533
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,...
0
10461
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10190
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
10019
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...
1
7555
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
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
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2928
bsmnconsultancy
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...

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.