News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How does MASM handle circular include?

Started by gwapo, August 06, 2008, 11:41:15 AM

Previous topic - Next topic

gwapo

Hi,

How does MASM handle circular include?

My test:

[file1.asm]
include file2.asm

[file2.asm]
include file3.asm

[file3.asm]
include file2.asm ; causes circular include here

When I try to compile the test, it reports "fatal error A1007: nesting level too deep"
instead of giving a better message suggesting that a circular include may have happened.,
or doesn't MASM handle checking of circular includes?

Well, we can wrap the code with IFNDEF SYMBOL/ENDIF to prevent the code inside it from
being used twice. But since this is a preprocessor statements, it's still loaded twice or more.

Tedd

Quote from: gwapo on August 06, 2008, 11:41:15 AM
How does MASM handle circular include?

  :

When I try to compile the test, it reports "fatal error A1007: nesting level too deep"
instead of giving a better message suggesting that a circular include may have happened.,
or doesn't MASM handle checking of circular includes?
Your test would indicate that, quite simply, it doesn't handle it at all :bdg (It just keeps including until it overflows its recursion stack.)

Quote
Well, we can wrap the code with IFNDEF SYMBOL/ENDIF to prevent the code inside it from
being used twice. But since this is a preprocessor statements, it's still loaded twice or more.
Yes, that's the usual way to do it -- and as long as you put the "include" statement inside the guard, each file will only be loaded once.
No snowflake in an avalanche feels responsible.

hutch--

 :bg

Thats why the masm32 include files have a duplicate guard.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gwapo

I was thinking that it might be a great feature for new assembler to include this kind of checking.

Something like the #pragma once in C++:

#pragma once  // mark by filename rather that just using include guard

Which will include the file then mark the filename as "included" so the next time that same file
is requested to get included, it just points to the previously loaded same file.

:bg

hutch--

Chris,

Why try to improve on a very reliable system,


IFNDEF _wininc_
_wininc_ equ <1>

  ; file content

ELSE
echo ------------------------------------------
echo WARNING Duplicate include file windows.inc
echo ------------------------------------------
ENDIF


You only get one copy and it tells you there is an attempt to load another.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gwapo

Yes, that's the currently available include guarding technique used on MASM and other assemblers, but it has some limitation:

1. It is using a symbol to determine if it will perform the include (preprocessor).
    In your example, if by any chance that somebody on the team already have _wininc_ definition somewhere
    else in the program then windows.h won't get included (or the part that's wrapped inside the IFNDEF/END
    compound).

    Well, that's easy enough to catch on small projects, but it will be a nightmare when we are talking about
    big projects with many programmers working on it.

2. Assembler is still loading the file. So, whatever codes that's outside IFNDEF/END compound will be included
    as well. "#pragma once" is good because the file will be checked for `include mark' prior to opening it.

I'm posting this because this board is frequented by many good programmers who are working with "assembler"
like JASM, HLA, PoASM etc., so maybe they can adapt that small feature for their future release.

:toothy

hutch--

Chris,

I imagine if they are not working with the same set of include files they are in trouble anyway. Properly guarded includes work on any size project where incorrectly set up includes will break a small project. MASM will tolerate some duplication but its not a good technique.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php