Variable declaration between function name and first curly brace

旧时模样 提交于 2019-12-18 18:47:34

问题


I am reading an article about code obfuscation in C, and one of the examples declares the main function as:

int main(c,v) char *v; int c;{...}

I've never saw something like this, v and c are global variables?

The full example is this:

#include <stdio.h>

#define THIS printf(
#define IS "%s\n"
#define OBFUSCATION ,v);

int main(c, v) char *v; int c; {
   int a = 0; char f[32];
   switch (c) {
      case 0:
         THIS IS OBFUSCATION
         break;
      case 34123:
         for (a = 0; a < 13; a++) { f[a] = v[a*2+1];};
         main(0,f);
         break;
      default:
         main(34123,"@h3eglhl1o. >w%o#rtlwdl!S\0m");
         break;
      }
}

The article: brandonparker.net (No longer works), but can be found in web.archive.org


回答1:


It's the old style function definition

void foo(a,b)
int a;
float b;
{
// body
}

is same as

void foo(int a, float b)
{
// body
}

Your case is same as int main(int c,char *v){...} But it's not correct.

The correct syntax is : int main(int c, char **v){...}

Or, int main(int c, char *v[]){...}

EDIT : Remember in main() , v should be char** not the char* as you have written.

I think it's K & R C style.




回答2:


It is a pre-ANSI C syntax for function declaration. We don't use it anymore. It is the same as:

int main(int c, char *v)


来源:https://stackoverflow.com/questions/13789450/variable-declaration-between-function-name-and-first-curly-brace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!