Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.05.27;
Скачать: CL | DM;

Вниз

Вопрос по C, прошу прощения что не там.   Найти похожие ветки 

 
GEd   (2007-04-30 22:19) [0]

Почему не работает макрос assert?
#include <assert.h>

int main(){
   int n = 0;
   freopen("error.txt","w",stderr);
   assert(n);
   return 0;
}
Он должен выводить диагностическое сообщение, но файл "error.txt" пустой!
Помогите, пожалуйста!


 
ArtemESC ©   (2007-04-30 22:22) [1]

Здесь кажеться форум под Delphi или я ошибаюсь :)


 
palva ©   (2007-04-30 22:40) [2]

ArtemESC ©   (30.04.07 22:22) [1]
Здесь форум по PHP


 
GEd   (2007-04-30 22:40) [3]


> ArtemESC


ты ошибаешься...


 
ferr ©   (2007-04-30 22:45) [4]

Зачем MSDN придумали а?
// crt_assert.c
// compile with: /c
#include <stdio.h>
#include <assert.h>
#include <string.h>

void analyze_string( char *string );   // Prototype

int main( void )
{
  char  test1[] = "abc", *test2 = NULL, test3[] = "";

  printf ( "Analyzing string "%s"\n", test1 ); fflush( stdout );
  analyze_string( test1 );
  printf ( "Analyzing string "%s"\n", test2 ); fflush( stdout );
  analyze_string( test2 );
  printf ( "Analyzing string "%s"\n", test3 ); fflush( stdout );
  analyze_string( test3 );
}

// Tests a string to see if it is NULL,
// empty, or longer than 0 characters.
void analyze_string( char * string )
{
  assert( string != NULL );        // Cannot be NULL
  assert( *string != "\0" );       // Cannot be empty
  assert( strlen( string ) > 2 );  // Length must exceed 2
}


Analyzing string "abc"
Analyzing string "(null)"
Assertion failed: string != NULL, file crt_assert.c, line 24

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application"s support team for more information.


 
Meow   (2007-04-30 22:56) [5]

GEd

скорее всего, проблема в том, что буфер не успевает сбросится до вызова assert.
попробуй написать чего-нибудь в stderr и сделать fflush.



Страницы: 1 вся ветка

Текущий архив: 2007.05.27;
Скачать: CL | DM;

Наверх




Память: 0.45 MB
Время: 0.044 c
11-1160134748
Thaddy
2006-10-06 15:39
2007.05.27
tip to reduce memory when inactive.


11-1141729246
Ал
2006-03-07 14:00
2007.05.27
И снова antialiasing


2-1178624343
Rimd
2007-05-08 15:39
2007.05.27
CopyFile(PChar(OldFile),PChar(NewFile),False)


2-1177655982
ОльгаС
2007-04-27 10:39
2007.05.27
Ehlib и инсталяция


2-1178650624
ММК
2007-05-08 22:57
2007.05.27
Включение с Windows





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский