|
yeap: rule, do not allocate memory to copies.
Still I don't understand what happens internally. In the bellow code ptOut will be a parameter on the internal Stack? How are handled params which come as refs?
Internaly all the params, pointers etc.. have also their own address? Or they are taken like some kind of aliases.
class CTest
{
private:
char *a;
public:
CTest(int n=10)
{
a= new char[10];
a="george";
}
void GetPtrEx2(char* &ptOut)
{
ptOut=a;
}
};
modified 21-Jan-13 13:55pm.
|
|
|
|
|
In the function GetPtrEx2() the address of the parameter will be passed on the stack. So with the assignment you change the address the pointer you called the function with points to.
You should however check your constructor. I don't think it will work as intended.
|
|
|
|
|
I while ago I wrote a Visual C++ program which included 3 calls of the function 'rename(x,y)' (rename file x as y, where x and y are char*), to swop the names of two files . It works.
x=rename(orig,w); y=rename(cor,orig); z=rename(w,cor);
A day or 2 ago I wrote a similar program which calls the same. And all 3 calls of 'rename' do not rename the file but give result -1 = "unknown error". Please what might cause this?
|
|
|
|
|
Right after the failed function use strerror(errno) to get a human readable error message:
#include <stdio.h>
#include <string.h>
#include <errno.h>
....
rename(x, y); printf("Error renaming %s to %s. Reason: %s\n", x, y, strerror(errno));
....
}
|
|
|
|
|
I did use strerror(errno), and it said "unknown error".
|
|
|
|
|
Check the values of all your file names when you call the function. Also what is the actual value of errno when the call returns?
|
|
|
|
|
> Also what is the actual value of errno when the call returns?
It is -1.
|
|
|
|
|
OK, you need to show a bit more of your code and the actual values of the old and new filenames that you are trying to rename.
|
|
|
|
|
The program text is
x=rename(orig,tempname); y=rename(cor,orig); z=rename(tempname,cor);
where x y z are integers and tempname cor tempname are big char arrays.
This is to swop the names of two files.
I run in the mode "Use Multi-Byte Character Set".
The string values are:-
orig = 'C:\Poser4\Runtime\Libraries\character\Divers\Divers_rebreathers\CDBA\cdba3_fr_hv_lm___2.cr2'
cor = 'C:\Poser4\Runtime\Libraries\character\Divers\Divers_rebreathers\CDBA\cdba3_fr_hv_lm___2_zz02.cr2'
tempname = 'C:\Poser4\Runtime\Libraries\character\Divers\Divers_rebreathers\CDBA\MIAOW_EE_EE_SAID_THE_CAT.txt'
The apostrophes are not in the strings.
The whimsical nature of tempname is to avoid coinciding with any permanent file.
I tested, and the temporary file does not exist already.
|
|
|
|
|
You are not checking the response after each rename to see if it succeeded, nor are you showing the value of errno .
|
|
|
|
|
x=rename(orig,tempname); if(x) MessageBox(0,strerror(errno),"rename file",OUCH);
y=rename(cor,orig); if(x) MessageBox(0,strerror(errno),"rename file",OUCH);
z=rename(tempname,cor); if(x) MessageBox(0,strerror(errno),"rename file",OUCH);
For "x=rename(orig,tempname);" the error was "permission denied"!!! This is on my own computer at home.
Sorry. I misread the help file. I thought that rename() returned errno as its return value. Sorry.
modified 20-Jan-13 11:29am.
|
|
|
|
|
Yes, and in each case you are checking the variable x even though you use y and z to store the other return values. If you get "permission denied" (so errno is not -1), then you are trying to rename a file or directory for which you don't have access rights. What version of Windows is this?
|
|
|
|
|
> you are checking the variable x
Thanks Sorry.
#define OUCH MB_ICONEXCLAMATION
x=rename(orig,tempname); if(x) MessageBox(0,strerror(errno),"rename file",OUCH);
y=rename(cor,orig); if(y) MessageBox(0,strerror(errno),"rename file",OUCH);
z=rename(tempname,cor); if(z) MessageBox(0,strerror(errno),"rename file",OUCH);
> What version of Windows is this?
Windows Vista. Thanks for all your help and patience.
|
|
|
|
|
Anthony Appleyard wrote: Windows Vista. You will find that the C: directories have protected access. You can adjust the protection levels or run with Administrator privileges. A better idea is not to work there, but use one of your user library locations for your data files.
|
|
|
|
|
> You can adjust the protection levels or run with Administrator privileges
How do I switch to running in administrator mode?
The usual user mode that I am in when I start my PC, please how can I make that user authenticated?
When did all this about several users and an administrator start in desktop PC's? When desktop computers came in, I was thankful that at last I was master of my computer and free from complications of several users and usernames and having to appeal to an administrator for things like when a computer was as big as a car and needed its own room.
Which privilege does a user need to move a file using rename(,)? My program makes no objection about reading and writing to files in the C:\ area.
I have a very similar Visual C++ project which does not refuse to rename files in my C: area.
When my Visual C++ compiler is working on this program, do I have to click "Project" on the top menu and then Properties on the resulting dropdown menu to make that project compile a program with the privilege to move files?
I have seen many changes in computers. I remember when the fastest data link available to me between the two parts of the university that I worked in, was me walking along Upper Brook Street with a magnetic tape about a foot (= 30 cm) diameter under my arm.
modified 20-Jan-13 17:40pm.
|
|
|
|
|
Anthony Appleyard wrote: How do I switch to running in administrator mode? You can right click the program in Windows Explorer and click "Run as administrator". Alternatively you can use the Project Properties: select Linker -> Manifest File, and change the UAC Execution Level to either "highestAvailable" or "requireAdministrator". This is always assuming that you are already running under an account with administrator level access.
Anthony Appleyard wrote: When did all this about several users and an administrator start in desktop PC's? It started with Windows XP and gets progressively more sophisticated with Vista and Windows 7.
Anthony Appleyard wrote: I have a very similar Visual C++ project which does not refuse to rename files in my C: area. So it would be a good idea to investigate what is different between the two.
|
|
|
|
|
> You can right click the program in Windows Explorer and click "Run as administrator".
> Alternatively you can use the Project Properties: select Linker -> Manifest File,
> and change the UAC Execution Level to either "highestAvailable" or "requireAdministrator".
I just now tried all 3 of these and all got "Permission denied".
> This is always assuming that you are already running under an account with administrator level access.
Please, how do I set my PC's current account to administrator level access?
If there is a file whose full name is "C:\\zxcvbnm", please how can I find if it exists, and of so, if it is open to anything, and if so, to close it?
I remember from way back (it may have been when I was still using Borland C++ 5.1) that I had a program that faulted, and it behaved correctly after I changed its compiling-and-linking mode from 'dynamic' to 'static'. Please how can I do that now in my Visual C++ 2008?
I have just checked, and as far as I can tell, my PC has one user, which is "Owner Administrator".
modified 21-Jan-13 5:03am.
|
|
|
|
|
Anthony Appleyard wrote: how do I set my PC's current account to administrator level access? You should have done that at install time. If you have the password of the admin account then you should login to that account and then use Control Panel -> Users to set your own account to administrator level.
|
|
|
|
|
Anthony Appleyard wrote: The apostrophes are not in the strings. What about the single backslashes?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
> What about the single backslashes?
In the strings in the program, the backslashes are double.
|
|
|
|
|
errno does not have a value of -1.
|
|
|
|
|
Recapping scattered comments.
After EACH method call IMMEDIATELY check the return value.
if the return value is not zero then IMMEDIATELY call errno. Do NOT make any other API calls before calling errno.
So you code should look like the following (with the included suggestion of strerror
int ret = rename(...);
if (ret != 0)
{
int errNum = errno;
printf("Failed to rename %s", strerror(errNum));
}
|
|
|
|
|
I just found that I had fopen()'ed the same file twice without fclose()'ing it between. The offending rename(,)'s now work OK. I am sorry to take up so much of your time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I just now inserted into my program this instruction:-
i=rename("C:\\Poser4\\Runtime\\Libraries\\character\\Divers\\Divers_rebreathers\\CDBA\\miaow.txt",
"C:\\Poser4\\Runtime\\Libraries\\character\\Divers\\Divers_rebreathers\\CDBA\\wuff.txt");
to rename a file which I had just created and the program never opens it. And the rename went OK.
The file that I was trying to rename it before :: I had fopen()'ed it in read mode, and read from it, and then fclose()'ed it; after that I tried to rename it, and that rename was refused.
modified 21-Jan-13 6:13am.
|
|
|
|
|
Hello, first of all I have to apologise if my question is stupid or asked in the wrong place.
I'm rather new to mpi and i just discovered how to achiave a topology aware communicator, using mpi_graph_create. The thing that I cannot seem to achieve is to track messages through said topology.
For example if I call MPI_Send/MPI_Recv is 2 "non-adjacent" processes, is there a way to check the route that message takes through the graph?
|
|
|
|
|