Maximum Method Name Length

2019-01-08 19:37发布

Does anyone happen to know what the maximum length of a method name is in your programming language of choice? I was going to make this a C# specific question, but I think it would be nice to know across the spectrum.

What are the factors involved as well:

  • Does the language specification limit this?
  • What does the compiler limit it to?
    • Is it different on 32bit vs 64bit machines?

10条回答
虎瘦雄心在
2楼-- · 2019-01-08 20:25

in Progress (OpenEdge) the limit is 32 char.

查看更多
Anthone
3楼-- · 2019-01-08 20:26

in C# is 511 characters length.

查看更多
在下西门庆
4楼-- · 2019-01-08 20:36

In D I don't know this to be the case but I suspect that it is something insane like >100MB. It might be an out-of-memory thing. This is based on knowing that I and other people have run into object file format limitation of about 11kB for symbol names and that this has been fixed.

查看更多
我命由我不由天
5楼-- · 2019-01-08 20:43

PHP seems to be limited only by the script's memory limit.

With 128Mb I was able to create a class (and method) with 4 million characters.

<?php
ini_set('memory_limit', '128M');
$i = 1024 * 1024;

while ($i < 10000000)
{
    $className = str_repeat('i', $i);
    eval("class $className { public function $className() { echo '$i<br>'; } }");
    new $className();
    $i *= 2;
}

?>
查看更多
登录 后发表回答