Здравствуйте, Pavel Dvorkin, Вы писали:
PD>В Форране есть строки с нулем
PD>CHARACTER*10 STR
PD>STR= 'ABC'C
PD>Но пользователь может C забыть
PD>Изменять ее в Фортране нельзя — не могу я требовать от пользователя, чтобы он каждую строку в специальную функцию передавал
PD>CALL SUB('TEST STRING'C)
PD>имеет право и будет нормально
PD>CALL SUB('TEST STRING)
PD>может привести к проблеме
Насколько я знаю, в Фортране, когда передаёшь строку в функцию, как последний скрытый параметр передаётся максимальная длина этой строки. То есть, если мы делаем интерфейс между Фортран и C мы должны сишную функцию принимающую фортрановскую строку объявлять так:
void SUB(char*, unsigned)
иначе не скомпилится. правильно я понимаю?
А вот что будет при CALL SUB('TEST STRING'C), будет ли скрытый параметр?
Здравствуйте, Pavel Dvorkin, Вы писали:
PD>Здравствуйте, SergeyL, Вы писали:
SL>>char stringCopy[MAX_STRING_SIZE];
SL>>//в принципе, здесь можно сначала проверить имею-ли я доступ к этому куску памяти...
SL>>memcpy(&stringCopy[0],srcString,MAX_STRING_SIZE-1);
PD>Здесь и на AV недолго нарваться... Откуда ты знаешь, что из srcString можно копировать MAX_STRING_SIZE-1 ?
//в принципе, здесь можно сначала проверить имею-ли я доступ к этому куску памяти...
BOOL IsBadReadPtr(
CONST VOID *lp, // memory address
UINT_PTR ucb // size of block
);
Здравствуйте, Pavel Dvorkin, Вы писали:
PD>Здравствуйте, korzhik, Вы писали:
K>>А изменить код можно? Чтобы он передавал в C — функцию char* и длину строки?
PD>В Форране есть строки с нулем
PD>CHARACTER*10 STR
PD>STR= 'ABC'C
PD>Но пользователь может C забыть
А разве нельзя объявить так:
CHARACTER*10 STR[C]
Если я правильно вспомнил...
Здравствуйте, SergeyL, Вы писали:
SL>SL>BOOL IsBadReadPtr(
SL> CONST VOID *lp, // memory address
SL> UINT_PTR ucb // size of block
SL>);
SL>
Larry Osterman’s Weblog, Confessions of an Old Fogey:
Should I check the parameters to my function?
The way you check for bad pointers on Win32 is by calling the IsBadReadPtr and IsBadWritePtr API. Michael Howard calls these APIs “CrashMyApplication” and “CorruptMemoryAndCrashMySystem” respectively. The problem with IsBadReadPtr/IsBadWritePtr is that they do exactly what they’re advertised as doing: They read and/or write to the memory location specified, with an exception handler wrapped around the read/write. If an exception is thrown, they fail, if not, they succeed.
There are two problems with this. The only thing that IsBadReadPtr/IsBadWritePtr verifies is that at the instant that the API is called, there was valid memory at that location. There’s nothing to prevent another thread in the application from unmapping the virtual address passed into IsBadReadPtr immediately after the call is made. Which means that any error checks you made based on the results of this API aren’t valid (this is called out in the documentation for IsBadWritePtr/IsBadReadPtr).
The other one is worse. What happens if the memory address passed into IsBadReadPtr is a stack guard page (a guard page is a page kept at the bottom of the stack – when the system top level exception handler sees a fault on a guard page, it will grow the threads stack (up to the threads stack limit))? Well, the IsBadReadPtr will catch the guard page exception and will handle it (because IsBadReadPtr handles all exceptions). So the system exception handler doesn’t see the exception. Which means that when that thread later runs, its stack won’t grow past the current limit. By calling IsBadReadPtr in your API, you’ve turned an easily identifiable application bug into a really subtle stack overflow bug that may not be encountered for many minutes (or hours) later.
Здравствуйте, korzhik, Вы писали:
K>Насколько я знаю, в Фортране, когда передаёшь строку в функцию, как последний скрытый параметр передаётся максимальная длина этой строки. То есть, если мы делаем интерфейс между Фортран и C мы должны сишную функцию принимающую фортрановскую строку объявлять так:
K>K> void SUB(char*, unsigned)
K>
K>иначе не скомпилится. правильно я понимаю?
Скомпилируется что угодно, работать не будет.

Если в фортране функция описана как имеющая С интерфейс, это не делается.