- 论坛徽章:
- 0
|
我写了一个代码:发觉如果不加入srand可以跑起来,但是如果不注释掉srand则会产生错误。请各位牛人看看,到底怎么了?
/*****************************************
FileName: main2.c
Description: test static/dynamic library
Author: HCJ
Date : 2005-5-7
******************************************/
#include<stdio.h>
#include<dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define MAX_TEST 100
int main(int argc, char* argv[])
{
srand((int)time(NULL));
int(*pCheckUser)(unsigned long ulClientIP, unsigned long ulUin);//定义函数指针
int(*pCheckIpLimit)(unsigned long ulClientIP, unsigned long ulUin);//定义函数指针
void *pdlHandle;
char *pszErr;
unsigned short i=0;
unsigned long uip=0;
unsigned short count=0;
if(argc<2)
{
printf("usage:dynamic_test <ip>\n");
exit(1);
}
pdlHandle = dlopen("./libcheckuser.so", RTLD_LAZY); //加载链接库/libstr.so
if(!pdlHandle)
{
printf("Failed load library\n");
}
pszErr = dlerror();
if(pszErr != NULL)
{
printf("%s\n", pszErr);
return 0;
}
//get function from lib
pCheckUser = dlsym(pdlHandle, "CheckUser"); //获取函数的地址
pszErr = dlerror();
if(pszErr != NULL)
{
printf("%s\n", pszErr);
return 0;
}
pCheckIpLimit = dlsym(pdlHandle, "CheckIpLimit");
pszErr = dlerror();
if(pszErr != NULL)
{
printf("%s\n", pszErr);
return 0;
}
if(inet_addr(argv[1]) != INADDR_NONE)
{
uip = inet_addr(argv[1]);
uip = ntohl(uip);
}
for(i=0;i<MAX_TEST;i++)
{
if((*pCheckIpLimit)(uip,0)>0)
count++;
}
printf("success probability is %d!\n",count);
dlclose(pdlHandle);
return 0;
}
怎是搞不懂?居然会有有一下错误?????
dynamic_test.c: In function `main':
dynamic_test.c:23: parse error before `int'
dynamic_test.c:35: `pdlHandle' undeclared (first use in this function)
dynamic_test.c:35: (Each undeclared identifier is reported only once
dynamic_test.c:35: for each function it appears in.)
dynamic_test.c:40: `pszErr' undeclared (first use in this function)
dynamic_test.c:47: `pCheckUser' undeclared (first use in this function)
dynamic_test.c:54: `pCheckIpLimit' undeclared (first use in this function)
dynamic_test.c:63: `uip' undeclared (first use in this function)
dynamic_test.c:66: `i' undeclared (first use in this function)
dynamic_test.c:70: `count' undeclared (first use in this function) |
|