(K&R) At least the first 31 characters of an internal name are significant?

后端 未结 5 942
独厮守ぢ
独厮守ぢ 2020-12-14 20:18

When taken literally, it makes sense, but what exactly does it mean to be a significant character of a variable name?

I\'m a beginning learner of C using K&R. He

相关标签:
5条回答
  • 2020-12-14 20:38

    G'day,

    One of the problems with this limited symbol resolution occurs at link time.

    Multiple symbols with the same name can exist across several libraries and the link editor usually only takes the first one it finds that matches what it is looking for.

    So, using S.Lott's example from above, if your link editor is searching for the symbol "a_very_long_name" and it finds a library on its search path that contains the symbol "a_very_long_name_thats_too_similar" it will take this one. This will happen even if the library that contains the symbol that you want, i.e. "a_very_long_name" has been specified in your command. For example specifying the libraries as:

    -L/my/library/path -lmy_wrong_lib -lmy_correct_lib
    

    There are now compiler options, or more correctly compile time options which are passed through to the link editor, which enforce a search for multiple symbols in your link path. These are then usually raised as errors at link time.

    In addition, many compilers, e.g. gcc, will default to such behaviour. You have to explicitly enable multiple definitions to allow the link editor to proceed without raising a fatal error if it finds multiple definitions for a symbol.

    BTW I'd highly recommend working through the exercises in conjunction with Clovis Tondo's book "The C Answer Book 2nd ed.".

    Doing this really helps make C stick in your mind.

    HTH

    cheers,

    0 讨论(0)
  • 2020-12-14 20:48

    It means that :

    foobar1
    foobar2
    

    might be the same external name, because only the first 6 characters need be considered. The single case means that upper and lower case names need not be distinguished.

    Please note that almost all modern linkers will consider much longer names, thogh there will still be a limit, dependent on the linker.

    0 讨论(0)
  • 2020-12-14 20:51

    It means what you fear it means. For external names, the C standard at the time K&R 2nd ed. was written really does give only six case-insensitive characters! So you can't have afoobar and aFooBaz as independent entities.

    This absurd limitation (which was to accommodate legacy linkers now long-gone) is no longer relevant to any environment much. The C99 standard offers 31 case-sensitive characters for external names and 63 internally, and commonly-used linkers in practice support much longer names.

    0 讨论(0)
  • 2020-12-14 20:53

    It just means that if you have two variables named

    abcdefghijklmnopqrstuvwxyz78901A,

    and

    abcdefghijklmnopqrstuvwxyz78901B,

    that there is no guarantee that will be treated as different, separate variables...

    0 讨论(0)
  • 2020-12-14 20:58

    Single Case usually means "lower case". Except in some OS's where it means "upper case". The point is that mixed case is not guaranteed to work.

    abcdef
    
    ABCDEF
    

    differ only in case. This is not guaranteed to work.

    The "Significance" issue is one of how many letters can be the same.

    Let's say we only have 6 significant characters.

    a_very_long_name
    
    a_very_long_name_thats_too_similar
    

    Look different, but the first 16 characters are the same. Since only 6 are significant, those are the same variable.

    0 讨论(0)
提交回复
热议问题