|
Whether you place extern on a variable definition or not makes absolutely no difference to where it is stored in memory.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
This depends on the compiler which is used.
Everything I have read about this suggests that the Visual C++ compiler treats the REGISTER keyword with very low priority (i.e. it uses it as a suggestion, but does what it thinks is best.)
I was doing some code which I though would benefit from keeping some three 32-bit variables in registers, but the REGISTER keyword made no difference to the speed. Looking at the assembly code which was generated, the three variables were not put in registers.
|
|
|
|
|
normanS wrote: Everything I have read about this suggests that the Visual C++ compiler treats the REGISTER keyword with very low priority (i.e. it uses it as a suggestion, but does what it thinks is best.)
Actually, it's even lower. It ignores it completely, as do most compilers these days. Generally, the optimiser is a lot better at choosing which variables should be in registers than the programmer is.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I saw that MSDN says:
"The compiler does not accept user requests for register variables; instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on."
I wonder if MS compilers have ever done anything with the register keyword.
I'm sure I still have a Visual C++ 1.52c disk somewhere at home - maybe I should install that (Win 9x?) and see what assembler that generates.
|
|
|
|
|
normanS wrote: I'm sure I still have a Visual C++ 1.52c disk somewhere at home - maybe I should install that (Win 9x?) and see what assembler that generates.
I think you'll find that it honours the register variables sometimes, and sometimes does not. C/C++ optimisers were still not very advanced back in 1993
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
rajeevktripathi wrote: 1) As we know that if a variable is declered in a file (Let .c file) then we can access this variable from any other .c file by using "extern" key word...... Now Question is where this extern variable is stored in memory.
The extern keyword tells the compiler that the variable is defined in another compilation unit and so no new space is needed for it - It just makes a variable from one compilation unit available in another. NOTE: It is ignored if the variable is initialized.
rajeevktripathi wrote: 2) Is there any way to make this sure that if any variable is declared in some .c file then any other file can not access this variable.
Two popular ways to do this (in C++):
1. The preferred way is to enclose it in an anonymous namespace. i.e.
namespace
{
}
2. The old deprecated way is to put the keyword static before it.
In C only the 2nd option is available.
rajeevktripathi wrote:
3) where the variables are stored while execution of program (RAM, or Hard disk, or CPU Registers)..
The simple answer is RAM - Which is more or less correct. However if you want to knit-pick it is more complicated than this:
- Windows has virtual memory thus the memory that stores the variable could be paged out in which case it is stored on disk until it is paged back into RAM again.
- The compiler may use registers. Many things effect if this is the case, such as what optimizations are used, usage of the keyword register , the structure of the code and the "intelligence" of the compiler.
Steve
|
|
|
|
|
when u use the MapViewOfFile API and set the 'dwNumberOfBytesToMap' to a particular value say "x" and then when u get the return pointer value(say "y") of the buffer that MapViewOfFile API returns,
What happens when we try to write to the "y+x+1"th memory location.....will an error occour?
cheerz!
|
|
|
|
|
namaskaaram wrote: What happens when we try to write to the "y+x+1"th memory location.....will an error occour?
Yes. You'll get an access violation exception and your program will be terminated by Windows unless you handle the exception.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Or unless you happen to already own that memory, which is more unfortunate - harder to find bugs in your program. I would rather see an access violation any day than to try to figure out 'who' overwrote some of my own memory.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Yes. That would be a rare occurrence though because MapViewOfFile() returns addresses in a different address range to the addresses returned by allocating memory "normally". So unless you've called MapViewOfFile() twice, this probably won't happen.
But you're right
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
I wanna use Linkage C in my code in visual Studio 2003 ,
when i add library file in Tools/Options in Lib section (in these case
my library is C:\WINDDK\3790\lib\wxp\i386)
I get linker error ! that can not resolve some things.
test error LNK2019: unresolved external symbol @_RTC_CheckStackVars@8 referenced in function "unsigned int __stdcall ATL::_AtlGetThreadACPThunk(void)" (?_AtlGetThreadACPThunk@ATL@@YGIXZ)
test error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
test error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
test error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function "unsigned int __stdcall ATL::_AtlGetThreadACPThunk(void)" (?_AtlGetThreadACPThunk@ATL@@YGIXZ)
test error LNK2001: unresolved external symbol __RTC_CheckEsp
test error LNK2001: unresolved external symbol __RTC_CheckEsp
test error LNK2001: unresolved external symbol __RTC_Shutdown
test error LNK2001: unresolved external symbol __RTC_Shutdown
test error LNK2001: unresolved external symbol __RTC_Shutdown
test error LNK2001: unresolved external symbol __RTC_InitBase
test error LNK2001: unresolved external symbol __RTC_InitBase
test error LNK2001: unresolved external symbol __RTC_InitBase
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function "unsigned int __stdcall ATL::_AtlGetThreadACPThunk(void)" (?_AtlGetThreadACPThunk@ATL@@YGIXZ)
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
test error LNK2001: unresolved external symbol @__security_check_cookie@4
But i have not any problems in Visual Studio 6.0.
can anyone help me?
Best Regards.
M.J.M.
|
|
|
|
|
I have a c++ progeam calling a subroutine. The variables are passed correctly, But just step into the subroutine at the first line under the subroutine header by break point, I got error message: "debug assertion failed"
.......
.......
complexFFT(sd_l,np_seed,np_seed1,isign);
.......
.......
void CData_vib_procDlg::complexFFT(float data[],unsigned int &number_of_samples,unsigned int &sample_rate,int &sign)
{
|
|
|
|
|
An assertion has failed. Check the parameters you are passing to the function. Sorry about the vague answer but with the information you give I don't think it can be narrowed down much further. Give us more details/source code if you want us to give you a more detailed response.
eg where are sd_l, np_seed, np_seed1, isign defined, and what types are they? What values do they have? What is the exact assertion?
The assertions are there for debugging usually to tell you that something you you sent the function is invalid.
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
|
|
|
|
|
sd_l is a float type array - sd_l[i], i=0,1,...np_seed-1, np_seed and np_seed1 are unsigned int,
np_seed1 = 4096
void CData_vib_procDlg::complexFFT(float data[],unsigned int &number_of_samples,unsigned int &sample_rate,int &sign)
{ ........
-- modified at 0:04 Tuesday 11th April, 2006
|
|
|
|
|
How to store a Binary value in a variable?
as we do for hexadecimal value as x=00XF88.how do we
store binary value like this?
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
You can't specify a binary literal directly. Specify it as octal or hex instead.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
hey, trying to send a DLL written in C with VC6, an integer from a VB6 app. I send it as an integer, it arrives as a u_int and is always 0. I accept the integer using a function, not a callback. I tried sending the value as a string and atoi()ing it, same results. I sprintfed the value and MessageBoxed it, which is how I know it is always 0 before usage.
How do I make the value keep its value when sent from VB6 app to VC6 DLL?
If you need more info, code or something, let me know. Thanks in advance.
|
|
|
|
|
Here's a tip.
In VB6, Integers are 16 bit and Longs are 32 bit.
You'll need to map a VB6 Long to a C/C++ int.
-- modified at 23:22 Monday 10th April, 2006
|
|
|
|
|
Should I do that on the C side? I assume you mean to send the long value to the DLL function and do the conversion there. Can't find any info on how to make that conversion on the VB side, which I guess wouldn't make sense and would be redundant to do so. Let me know if I am headed in the right direction. I will continue to research it and check back here periodically. thanks in advance.
|
|
|
|
|
This isn't really a conversion issue. This is an issue with correctly defining the C function on VB6's side.
I suggest that you leave your C library alone (assuming it has worked fine before). Instead, you should fix the Declares in your VB6 code.
If the C function has a short , use an Integer type in VB6.
If the C function has an int , use a Long in VB6.
For example, if a C function is defined like this...
int Sum(short x, short y);
Then in VB6, it would be declared like this...
Private Declare Function Sum Lib "YourLib.dll" (ByVal x As Integer, ByVal y As Integer) As Long
|
|
|
|
|
hey, sorry for the late reply. I did what you suggested and it is now returning the proper integer on the C DLL side, but when it goes into my processing function, the value becomes 0 still. I should probably have told you that the processing function is created in its own thread --maybe that is why I am having trouble.
Basically the VB6 app sends the integer as long, it is recieved by a function and stored as u_int. The function calls the threaded function and the value should then be used in a for loop to determine how many times the for loop should loop.
Theo:
u_int *My_Var;
<Threaded_Function>
<for 0 to My_Var>
</for>
</Threaded_Funtion>
<function u_int *Sent_Variable>
myVar = Sent_Variable;
return 0;
</function>
So, that is pretty much it. Let me know if you need more info. Thanks in advance.
|
|
|
|
|
This sounds like an issue in your C library.
For starters, you might just want to comment out your C function's code and just have it return a constant. This will prove whether or not a call to your C library is working.
Next, I think you need to debug your C function's code because I suspect that's where the issue is. If you're using threads, then you could be running into race conditions.
If your C function makes a call to a threaded function, are you blocking the current thread while it's being processed? Otherwise the current thread will just fall through before the process completes (or even begins). Or are you making a separate call to your C library for the process result?
|
|
|
|
|
Is it possible to have a tree control with some items having checkboxes and others not?
ie) the root items to not have checkboxes, but the child items to have a checkbox.
|
|
|
|
|
Hello,
a question around the error C2666, under vc80 (RTM-8.0.50727.4200)
Is it compliant to the C++ standard ?
class CondParams
{
...
static bool getVariableState( const string& s, int& idx, string::size_type* p = NULL;
static bool getVariableState( string& rs, int& idxVar, const bool& trim );
);
bool CondParams::getVariableState( string& rs, int& idx, const bool& trim )
{
...
VCF::String::size_type p = 0;
bool ok = getVariableState( rs, idx, &p );
if ( ok ) rs = rs.substr( p );
...
}
I get the error message:
1>d:\projs\condparams.cpp(66) : error C2666: 'vcfex::CondParams::getVariableState' : 2 overloads have similar conversions
1> d:\projs\code\condparams.h(130): could be 'bool vcfex::CondParams::getVariableState(string &,int &,const bool &)'
1> d:\projs\code\condparams.h(129): or 'bool vcfex::CondParams::getVariableState(const string &,int &,string::size_type *)'
1> while trying to match the argument list '(string, int, size_type *)'
1> note: qualification adjustment (const/volatile) may be causing the ambiguity
I could fix the problem by doing:
1) static bool getVariableState( string& s, int& idx, string::size_type* p = NULL; // A
or by doing:
2) bool ok = getVariableState( const_cast<const string="">(rs), idx, &p );
so I guess that the compiler is confused because it doesn't find any perfect match.
The solution 1 is usually not acceptable.
So I have to apply 2).
But this situation is *very* common: why should I need to specify that a variable
is constant each time I am using it as argument for a function that declared that is not
going to modify it ?
Also it doesn't logically seem necessary.
It is like the Standard C++ ( or Microsoft? ) is forcing me to put a const_cast<const ...=""> everywhere.
This was not a problem with vc70.
Similar issue, but not identical, with an example given in vc80 RTM help about the C2666 error.
enum E
{
E_A, E_B
};
class A
{
int h(const E e) const {return 0; }
int h(const int i) { return 1; }
void Test()
{
h(E_A);
h((const int) E_A);
h((int) E_A);
}
};
Why the compiler shouldn't be smart enough to understand that
int h(const E e)
is a better match than
int h(const int i)
?
Why in earth
int h(const E e)
solves the problem, while
int h(const E e) const
does not ?
Thank you very much for any answer before I start to *fix* my code !
Marcello
|
|
|
|