|
What if p points to element 0 of the array? How would you check for this?
|
|
|
|
|
You can't. Not inside MoveBack() anyway. Which is yet another good argument not to meddle with pointers recklessly.
The only way to ensure a pointer is inside the scope of an array is to compare it to the start address, and only the function that defined the array knows it.
So if you really wanted a 'safe' MoveBack function, you'd have to add a parameter, like this:
MyStruct* MoveBack_s(const MyStruct* p, const MyStruct* parray)
{
MyStruct* result = 0;
if (p > parray)
result = p-1;
return result;
}
Of course, even this function is not safe if you pass it a pointer to the start of a different array...
The only way to be truly safe is not to use pointers, but iterators, such as those used for the STL class vector. They contain references to the container they refer to and therefore can check their boundaries themselves.
|
|
|
|
|
When using sizeof with a structure it is not guaranteed that you get the sum of the single components due to Structure padding (wiki for it). Just printf the sizeof() of your struct and you will see that its not 12 Bytes.
Anyway it is very unclear to me why are you even trying to do it this way. Dont mess with addresses and pointers in such an unsafe way. Who even tells you that you could just decrease the given int pointer and it would still point to a valid adress.
E.g. just use the indices of the array to get the last element.
|
|
|
|
|
I made a code snippet to print the size of his structure and it was in fact 12 bytes.
|
|
|
|
|
Well i was a bit fast with saying that it will not be 12 bytes. Of course it depends on the compiler. I just wanted to state that its not allways 12 bytes.
|
|
|
|
|
Why on earth was this rated as a bad answer?
Each of the points made are valid and important. Let's see if a 5 won't help!
|
|
|
|
|
Legor wrote: When using sizeof with a structure it is not guaranteed that you get the sum of the single components due to Structure padding
But it doesn't matter since you will always get the size of the actual structure as created by the compiler, so you can still use sizeof to increment a void pointer.
However, as you rightly point out, that is a stupid way to do it since normal increment/decrement or indexing is the correct way.
The best things in life are not things.
|
|
|
|
|
Hi all,
i have an list that contains some items say N items.
i have assigned x number of process to do processing over N List Items.
for example if (x=2) number of process work on processing of (N=20) List Items, so its start from starting two List items when any process finished first than move on 3 one and so on until last item of List.
so please help me how can i do this.
thanks in advance.
|
|
|
|
|
Cannot you use just threads instead of processes?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
when i use thread its end after execution of one list item? how can i set it like this first only assigned number of threads running and execute function on the bases of list item data, after execution check if list have any other item to be execute than execute this.
|
|
|
|
|
If I got you (the requirements aren't very clear), yes. However you should learn a bit how threads (or processes if you like) work. Have a look at: "About Processes and Threads"
[^] at MSDN.
Another worthy reading is the Newcomer's: "Thread and Processes series"[^] series.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Wednesday, July 13, 2011 3:22 AM
|
|
|
|
|
|
Sorry. Fixed now.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Well, you can have multiple processes work together by communicating between them using pipes or sockets, but like it was already suggested, threads would probably be the most applicable solution to this. If the processes are doing the same thing, there's a perfect example of using CWinThread derived threads, by deriving (or subclassing), its easy to make multiple instances of the desired thread.
|
|
|
|
|
If you do in fact mean 'process' then the first step in the solution is explaining exactly what form the 'list' takes.
|
|
|
|
|
list taking some information that is communicate using ports,
i am having 2 and more port number for communication.
one port can use details from list and communicate after finish it use another item to do this ,coz if i want to access the port that is already in use it gives an error of access denied.
so please help me how can i do this?
thanks in advance.
|
|
|
|
|
Beej's Guide to Network Programming
Not so much for threads and processes but for a great read on ports. If I have understood your need correctly, this reference should help you.
|
|
|
|
|
The "List Hold'n'Synchron Kernel" could lie in a singleton COM EXE-server,
while some its clients could:
- ask for a value associated with a cockie-ID from the server
- precess on that value
- send the modified value associated with the cockie-ID to the server
You could also play
with the different appartment models of the server...
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
can anybody please provide me any sample or example code.
|
|
|
|
|
Hi Developers,
I want to set the multi selection property of a list box as TRUE through the code, in OnInitDialog(). I can do it from the resource view( dialog box ), but that dialog has used in so many modules.
Thanks.
Amrit Agrawal
|
|
|
|
|
See the notes here[^], this property cannot be turned on programmatically.
The best things in life are not things.
|
|
|
|
|
Just replace your resource list box by a static box (IDC_STATIC_LIST, "VISIBLE" = false),
then create a member list box in the OnInitDialog() function
by usage of the client position of the IDC_STATIC_LIST, current resource styles,
and the (passed in dialog constructor) multiselection flag
(Do not destroy any child explicitly)
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Hi developers,
I want to handle TVM_DELETE or TVN_DELTEITEM from a custom tree control in other file( which is derived from CFormView ). From tree control, I am trying to send
<pre> SendMessage(TVM_DELETEITEM, WPARAM(0), LPARAM(hItem));
I have handled this msg in view file like this
<pre> ON_MESSAGE(TVM_DELETEITEM, OnTvmDeleteItem )
but it simply delete the item and doesn't caught at OnTvmDeleteItem().
I have also tried to send TVN_DELTEITEM with ON_NOTIFY_MESSAGE(), but still it doesn't work.
Pls help me out.
Thanks.
|
|
|
|
|
Amrit Agr wrote: I want to handle TVM_DELETE or TVN_DELTEITEM from a custom tree control in other file( which is derived from CFormView ). What do you mean by that? You want to give the implementation of the handlers for those notifications in a different file than the one that hosts your CFormView derivative's implementation?
Amrit Agr wrote: From tree control, I am trying to send
SendMessage(TVM_DELETEITEM, WPARAM(0), LPARAM(hItem));
You are sending that message from the tree control where? How? To where? TVM_DELETEITEM is sent TO the tree control usually to delete an item, not by the tree control.
Amrit Agr wrote: I have handled this msg in view file like this
ON_MESSAGE(TVM_DELETEITEM, OnTvmDeleteItem )
but it simply delete the item and doesn't caught at OnTvmDeleteItem(). This implies that you want to handle the delete-item in your custom tree control, is that correct?
Amrit Agr wrote: I have also tried to send TVN_DELTEITEM with ON_NOTIFY_MESSAGE(), but still it doesn't work. You use ON_NOTIFY_MESSAGE to catch messages, not to send them, what you say here is confusing.
Please try to explain a bit more clearly what exactly you are trying to do.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
I want to handle deletion of tree item in other file, because I have to do some database work.
But this custom tree is used in so many applications, so that I can't send to directly to any window. I have handled that TVM_DELETE message in other file, and assume It should get called. but it can't reach at the specified function.
Should I try PreTransalteMessage() in other file after mapping WM_KEYDOWM do the particular deletion and database work?
|
|
|
|