Re: Passing a constant by reference
Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance
Bob Altman wrote:
I want to call a function that takes a void* argument and pass it the address of
a constant. Is there a way to do this without explicitly defining the constant
and then passing the address of the constant? In other words, what I *don't*
want to do is this:
const int myInt = 5;
MyFunc(&myInt);
I want to do something more like this:
MyFunct(&(int)5);
A constant expression has no address; what you're asking for is meaningless.
It's like asking where the number 5 is stored in the computer. It's not
stored anywhere, it just *is*. Storage locations produce addresses, not
constant values. Aren't you accidentally confusing this with a literal
address, i.e.
MyFunc((void*) 5);
This will convert the integer 5 to a memory location and pass that as a
pointer. This will then most likely produce an access violation upon access,
since "5" is rarely a valid address, but if the "void*" is meant to merely
hold a pointer-sized value rather than an actual pointer, this might have
some meaning.
--
J.
http://symbolsprose.blogspot.com
.
Relevant Pages
- Re: Simple question, err... I think
... It's meaningless to then direct me to look at the code. ... quality of the code it felt safe to assume a leak :-)). ... Set B(Set l, int n, Set r) ... /All/ 'return' statements in this function return a pointer to a freshly ... (comp.programming) - Re: Using the Exchange Backup API
... Given that, Viraj, it seems to me that the function you are calling ... pointer, or maybe the computer name parameter is not allowed to be NULL? ... >> Given that you're getting an access violation exception, it makes me suspect that your pointer is ... You say that the GetProcAddress returned with a valid pointer, ... (microsoft.public.vc.mfc) - Re: Error in initializing ICaptureGraphBuilder2
... Access violation writing location 0xcdcdcdcd. ... You need to look at the stack trace. ... doesn't mean that the access violation occurs right at that statement. ... When the parameter for a function is a pointer to a pointer, ... (microsoft.public.win32.programmer.directx.video) - Re: Q: Cannot control vista api "SHGetKnownFolderPath" using shell32.dll in Delphi 7 on Windows XP.
... Okay, i think function pointer works good, but i don't know exactly ... Misdeclaring that last parameter is probably what's causing the access violation. ... function ShGetKnownFolderPath(const rfid: TGUID; dwFlags: DWord; hToken: ... Now the rest of your program can simply call ShGetKnownFolderPath, just as though it were a normal API function. ... (alt.comp.lang.borland-delphi) - Re: Q: Cannot control vista api "SHGetKnownFolderPath" using shell32.dll in Delphi 7 on Windows XP.
... pointer by dynamic-load "shell32.dll". ... Okay, i think function pointer works good, but i don't know exactly ... causing the access violation. ... as though it were a normal API function. ... (alt.comp.lang.borland-delphi) |
|