简体   繁体   中英

Variable declaration between function name and first curly brace

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM