|
OK, I agree, such coding requires a good comment line to it, since the function might not be obvious to everyone.
|
|
|
|
|
I know that this code needs good documentation. But I like simple and less processor consuming codes. Further more, in my case there will not be negetive values. So I don't care about the behaviour of this logic with negetive values
- NS -
|
|
|
|
|
if (a%2==0) // number is even
a--; // make it odd
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
U can use like this also.
using conditional operator....
(num%2 == 0)? num : num - 1;
|
|
|
|
|
I think simplest is the one that kakan said. --num |= 1;
- NS -
|
|
|
|
|
|
Maximilien wrote: yeah, but it's unreadable.
Unreadble for whom?
|
|
|
|
|
I swear that there will be a good explanation for this in my cpp!
- NS -
|
|
|
|
|
|
First I thought about this one. But there is constraint in my requirement the new odd number should be less than the actual one if it is even.
So #define makeOdd(x) ((--(x)) |= 1) is required.
- NS -
|
|
|
|
|
I also think that -- =1 is the best solution, from many points of view, from performance to simplicity. That code will easily compile even on small microcontroller implementations without great effort, even those that do not have division capabilities (I've seen % posted on some replies, and that is surely a waste of resources).
I've also seen the question of operator precedence. Actually, that should not be a problem, since, generally speaking, --x means that x will be decremented *before* the value is used. That is the diference between --x and x--.
If anyone has doubts about the precedence then (--(x))|=1 will guarantee adequate precedence, as proposed by NS17. I would sugest to force the precedence to make reading easier, meaning that, in this way, it is not necessary to know the exact meaning of --x by heart, and that the correct evaluation will be explicit instead of implicit.
I would also sugest an improvement that allows for the macro proposed by NS17 to be used even when x is not an l-value. That would be:
#define makeOdd(x) ( ((x)-1) | 1)
This macro could then be used in all cases below:
x=makeOdd(x);
x=makeOdd(14);
z=makeOdd(x)+makeOdd(y);
Rilhas
|
|
|
|
|
Rilhas wrote: I would also sugest an improvement that allows for the macro proposed by NS17 to be used even when x is not an l-value. That would be:
#define makeOdd(x) ( ((x)-1) | 1)
Exactly... actually i was ignoring that thing, beacuse in my case the variable itself should be changed...
Anyway thank you for your replay...
- NS -
|
|
|
|
|
hi all,
i have to create a Transparent Edit Control in my dialog please tell me your advice.
thanks,
uday.
uday kiran
|
|
|
|
|
|
Compiling...
StdAfx.cpp
Compiling...
Read_XVI_Scan.cpp
Linking...
LIBC.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Release/Read_XVI_Scan.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
A colleague is getting the above error when compiling here at work with VC, but at home on his VC-Express edition it works OK.
I'm sure this is a simple setting not right somewhere, but am not sure where to start looking - I guess once you've fixed this kind of glitch a few times, you get used to knowing where to look?
thanks in advance for any help..
-- modified at 7:07 Wednesday 19th April, 2006
|
|
|
|
|
I thought I'd fixed it by making it a console app, but now I get the other error
Linking...
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/XVI_Read_Scan.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
searching codeproject I found this suggestion but don't know which tab/group this is in and couldn't find it by looking through them
"Usually this is caused by leaving the _ATL_MIN_CRT definition in your project settings when your code uses the C runtime libary startup code, either directly or indirectly. Remove the _ATL_MIN_CRT definition and rebuild all."
|
|
|
|
|
Ack, I couldn't find a "main" function in his code - added it and now it works of course!
|
|
|
|
|
Hi
I am creating a wipe utility which will wipe files, some application and system traces.
Here I want to include "WIPE OF PAGE FILE" ( in NT it is Pagefile.sys and in 9x it is WIN386.SWP) in the utility, where fill garbage value in this file.
I googled a bit about pagefile/ swap file and learned that it can be deleted at restart.
But I am not sure that how to proceed for deleting this file because pagfile is used by System, and when I try to open it ( say in WordPad) then error of sharing violation comes.
So please suggest me that how to overwrite pagefile.sys / WIN386.SWP files.
Please reply.
Thanks
--
|
|
|
|
|
AFAIK only a native app running at boot time can mess with the paging files. At other times, the paging file is in use for actual paging.
Not sure if this will help your situation, but there is a group policy setting that will make the OS zero out the page file when the system is shut down.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Ok, but please tell me the way how to overwrite pagefile.sys file with some garbage value, because when we open this file then it gives sharing violation error.
Please reply.
Thanks
|
|
|
|
|
So if Windows has important information paged out to this file, and your program comes along and deletes the file, what becomes of the information it once contained? That does not sound like a good idea.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thnaks for your suggetions,
Now I m trying to move files at boot time by using MoveFileEx( ), but this function even deletes the source file ( when we give second parameter NULL) at boot time, but does not move the file .
This is the code I am using
BOOL bMove;
bMove = MoveFileEx(_T("C:\\Rajeev.txt"), _T("C:\\MovedRajeev.txt"), MOVEFILE_DELAY_UNTIL_REBOOT);
int aaa = GetLastError();
Here bMove returns 1 and aaa is 0
Please guide me that where I am wrong.
Thanks
|
|
|
|
|
rajeevktripathi wrote: Here bMove returns 1 and aaa is 0
Which means it was successful.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
yes it means it is successful but it does not move the fils at reboot.
Please give me the solution
Please reply.
Thanks
|
|
|
|
|
So does HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations exist in the registry after the function returns, and is it gone when Windows is restarted?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|