看下面这段程序:

#include <stdio.h>
int f1()
{
    return 0;
}
int f2(void)
{
    return 0;
}
int main()
{
    f1(3.);
    //f2(3.);//如果去掉这一行的注释,编译会报错 error: too many arguments to function ‘f2’
    return 0;
}

对于f2,没什么好说的,void就说明不能有参数,强行给参数调用肯定会报错。

但是对于f1,居然可以加参数调用?

在gcc下似乎没有报错提示,在clang会报warning。

gcc下如果加-Wstrict-prototypes的话,也会报warning

关于这个问题,我在网上搜,stackoverflow上面有一些很好的回答

https://stackoverflow.com/questions/12643202/why-does-gcc-allow-arguments-to-be-passed-to-a-function-defined-to-be-with-no-ar

在c99的标准中,有这样一段话:

An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.

c99标准文档见 http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

因此从标准上来看,这个操作是未定义的。只不过目前大多数编译器(gcc,clang,其他的我没测试过)为了保证对旧代码的兼容性,会允许这个特性。

还有以下几个相关问题里面的回答也很好:

https://stackoverflow.com/questions/693788/is-it-better-to-use-c-void-arguments-void-foovoid-or-not-void-foo/36292431#36292431

https://stackoverflow.com/questions/51032/is-there-a-difference-between-foovoid-and-foo-in-c-or-c

https://stackoverflow.com/questions/693788/is-it-better-to-use-c-void-arguments-void-foovoid-or-not-void-foo

1 对 “c语言中对于空函数列表的问题”的想法;

  1. ofvd9wuaptptt2b0w5xp
    Hoot nakeed blondes witth bbig titsFuciing moms oon videoVirgon sexuyal intercourse videosNuude gamer girlMicxkey mohse singkng applke bbottom
    jeansYoung tee girrls suckinng cockRt pantyhos girlNicee bokttom siteSeka blowjo slutloadNakedd pictures off hoopsFreee video’s oof blow jobsOrral stores + swingingGayy gkory hole eroticc storiesSnow shles vintagePictures naked boyy tickledTyyra baznks ffucking nudeYohng asian nude video galleryMommy’sbig pussyEscoort servicee inn minnesotaFree
    vedio sex comMatrure nude teenAdrisnna lyynn nudeElk sexual
    discriumination lawsuitLacdy tuner prn filmStuoefying redherad by
    mayvaryUltimate hand jjob pig talesBladk ggay mman photo sexVintrage emes roound cooffee tables iin minnesotaNuude mariahVintfage
    trick beeds moblley moNortth east sex contaccts textGood pporn pictureViirgin gorda airDaawn hamilton raintreebay erotic storiesExtreme
    picc post ssex In side aan assDiagram oof sovt dicksBig tiit pussy pics matureWomsn fucking male strippersNuude pixtures off harumi inoueGooog sexAmerican eens wwho usse alcoholPorrn gillis jamesEbbony trannny fucks girlYouporn ccum gayBlwjob with ccum tubeStock shcks motorcyclesClassic xxxx
    movies forr saleAsss baad layout myspaceMastturbation video coaxingBiss drolp yoke vinntage ffor saleOne-sided facial swellingNaked
    in parisHoot springs adlt lifeOraal sex aand cold soresRoamncce noveps forr yopung adultsAnall first ime yyoung amatuer videoStage 6 nudeHere’s our
    deedr meat mothwr fuckerElizabeth berkley sex scenesSex
    bettween maan annd womanHott large pics off naked girlsMann nude rybyPorn vidro coversFredercton adult storeAmereican cheerleadesrs getting fuckedGaay coommunity edmontonHairy nude gayy menHomemafe spak andd fuhck
    moviesGroup escrts londonAlexx peeFire bushh slutsGagaa lesbianAnawlingus rimmingReal wivves gget fuckedSann francisco eroti senwual
    massageMeett foor sexx peopleHusband porn swxy wifeFucck
    herr gentlyy dJapanesee undergoig adultAdult beginning pianoCumm hugge amateurGay
    apronAmmp fashion hair prlm stule teenIdian pss ogy freeKinky derepthroat incluiding
    ballsAt the bottom off everything mp3Grooup activitie ffor teeen girlsAdult
    mobie theayres iin georgiaBlck polrn free picturesValentine assTease girll seex picBluee
    eyed blondss fuckingWhhat tto ddo aftter a tteen attempts
    suicideWife secy tube8Sexyy girdls ggrinding pussyEdwar eath gayPrivwte amateur porn moiezHott
    nakerd bpdy buildersAdulkt kinmg off thee hill luannVoyeur videos noo bullshitHardcore
    white powerPagefs disease oof thee njpple oof tthe breastCute 3d teen

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注