ã
ANSI Cã§ã¯
ããªããã»ããµãã¯ããç¨æããã¦ãã¾ãã
ã³ã³ãã¤ã«ã®åå¦çã¨ãã¦å®è¡ãããå®ç¾©æ¸ã¿ã®ãã¼ã¯ã³ãããããã決ããããå¤ã§ç½®ãæãã¦ãã
ã³ã³ãã¤ã©ã«æ¸¡ãã¨ããç©ã§ãã
Javaã§ãããã§ãããæè¿ã®è¨èªã§ã¯
ããªããã»ããµãã¯ãã®ããã«ãå¯ä½ç¨ã®å¤§ããªç©ã¯æé¤ãã¦ããããã«è¦ãã¾ããã¾ããã¯ãã®å»æ¢ã¯èª¤ãã®å°ãªãããã°ã©ã ãæ¸ãããã«ã¯æ£ããã¨æãã®ã§ãããããã§ããã¯ã使ãããç©ãããã¤ãããã¾ãã
ããã®çé ã__FILE__ã¨__LINE__ããããã¯
ã³ã³ãã¤ã«ã®åå¦çã§ãããã¡ã¤ã«ã®ãã«ãã¹ãã¨ããã¡ã¤ã«ã®è¡çªå·ãã¨ãã¦ç½®ãæãããã¾ããç¹æ®å®æ°(INT_MAXã¨ã)ã®ããã«ããã°ã©ã ã®åä½ã¨ãã¦ã¯å½¹ã«ç«ã¡ã¾ããããã¿ã°ã¸ã£ã³ãæ¸å¼ã®ãã°ãåãåºãã¨ãã¯çµæ§ä¾¿å©ãªã®ã§ããç§ã¯ãããªæãã§ä½¿ã£ã¦ãã¾ãã
wsprintf(szOutput, "%s(%d) lRet:%ld", __FILE__, __LINE__, lRet);
OutputDebugString(szOutput);
ãããã§ãVCã®
ãããã°ã¦ã£ã³ãã¦ã«ã¡ãã»ã¼ã¸ãããããã¨åºã¾ããç§ã®å ´åãPlatform
SDKä»å±ã®ãµã³ãã«ãdbmonã«ã¡ãã£ã¨æãå
¥ãã¦ãOutputDebugString()ã®åºåããã¡ã¤ã«ã¸åºåããæ¹è¯çã使ã£ã¦ãã¾ããä¸è¨ã®wsprintf()ãå®éã¯ãã«ãã¹ã«ç½®ãæãããã__FILE__ã§ã¯ãªãã
絶対ãã¹ãé¤ãããã¡ã¤ã«åãæ ¼ç´ããå¤æ°ãç¨æãã¦ä½¿ã£ã¦ãã¾ã(ã客ããã«ä¸ä¸è¦ããããããã ã)ã
ããã¦ã
C#ã使ãããã«ãªã£ã¦ãæ大ã®ä¸æºã
ããªããã»ããµãã¯ãããªããã¨(ã¨ãããã__FILE__,__LINE__ããªããã¨)ã§ãããã©ããã£ã¦ã¿ã°ã¸ã£ã³ãä»ãã®ãã°ã ããã¨æ©ãã§ãã¦ãããã£ã¦ã¿ãã¨ãã¯ãä¸çä¸ã§åãäºã§æ©ãã§ãã人ããã¾ãã
.NET 247 : hot to write __FILE__ and __LINE__ in C#ãã¾ãã«ããã
ãSystem.Diagnosticsã®StackFrameãªãã¸ã§ã¯ãã使ãã°ããã¨ã®ãã¨ããããªæãã
using System.Diagnostics;
void OutputError(string Message)
{
StackFrame CallStack = new StackFrame(1, true);
string SourceFile = CallStack.GetFileName(),
int SourceLine = CallStack.GetFileLineNumber(),
MyWriteToFile("Error: " + Message + " - File: " + SourceFile + "
Line: " + SourceLine.ToString());
}
ãããã§StackFrame()ã®
ã³ã³ã¹ãã©ã¯ã¿ã«1ã渡ãã¦ããã®ã¯ããä¸ã¤åã®ãã¹ã¿ãã¯ãåç
§ããã¨ãããã¨ã§ããã¤ã¾ãããã®OutputError()ãå¼ã³åºãç´åã®ä½ç½®ãåå¾ã§ããã¨ã
MSDNã®ãã«ã(2005/02/22ç¾å¨)ã«ã¯ããæ¸ããã¦ãã¾ãã
ã¹ã¿ã㯠ãã¬ã¼ã ã«ã¯å¿
ã MethodBase æ
å ±ãå«ã¾ãããªãã·ã§ã³ã§ãã¡ã¤ã«åãè¡çªå·ãããã³åçªå·ã®æ
å ±ãå«ã¾ãã¾ãã StackFrame æ
å ±ã¯ããããã° ãã«ãæ§æã¨å
±ã«ä½¿ç¨ããã¨æãæçãªæ
å ±ã¨ãªãã¾ããæ¢å®ã§ã¯ããããã° ãã«ãã«ã¯ãããã° ã·ã³ãã«ãå«ã¾ãããªãªã¼ã¹ ãã«ãã«ã¯å«ã¾ãã¾ããã
ãããããããªãªã¼ã¹ã§ã¯å°ãã®ã§ã¯ï¼ã¨æãã¾ãããã¯ããã¦ãã®éãããªãªã¼ã¹ãã«ãã§ãã
ã³ã³ãã¤ã«ãªãã·ã§ã³ã§ã
ãããã°æ
å ±ã®çæ:Trueã(å³)ã«ããªãã¨
ã¹ã¿ãã¯ãã¬ã¼ã¹åºãã¦ããã¾ããã§ãã(VS .NET2003)ããã¼ãããã ãªãã