English 中文(简体)
C程序 - 在汇编器中标为未申报的结构
原标题:C program - Structure marked as undeclared in compiler
  • 时间:2012-05-26 09:04:18
  •  标签:
  • c
  • structure

我试图写一个程序,收集文件的安全信息,并将其转换成人文可读信息。 然而,我面临着一个初始化一个指针结构的问题:

#include <stdio.h>
#include <aclapi.h>
#pragma comment(lib, "advapi32.lib")
struct file_perms {
    char user_domain[2050];
    unsigned long user_mask;
};
static myfunc (){

PSECURITY_DESCRIPTOR pSD = NULL;
PACL pDACL = NULL;
char *file = "D:/code/test.c";
ACL_SIZE_INFORMATION aclSize;

ULONG result = GetNamedSecurityInfo(file,SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pDACL, NULL, &pSD);
if (ERROR_SUCCESS != result) {
    printf( "GetNamedSecurityInfo Error %u
", result );
}
if(pDACL != NULL){printf ("2
");}
//ACL_SIZE_INFORMATION aclSize = {0};
ZeroMemory(&aclSize, sizeof(ACL_SIZE_INFORMATION));
    if(pDACL != NULL){   
        if(!GetAclInformation(pDACL, &aclSize, sizeof(aclSize),
            AclSizeInformation)){
            printf("GetAclInformation Error 
");
            return 0;
        }
        printf("AceCount %d
",aclSize.AceCount);
    }
file_perms *fp = new file_perms[aclSize.AceCount];

}

While compiling, I am getting the following error. getnamed.c

getnamed.c(34) : error C2065:  file_perms  : undeclared identifier
getnamed.c(34) : error C2065:  fp  : undeclared identifier
getnamed.c(34) : error C2065:  new  : undeclared identifier
getnamed.c(34) : error C2106:  =  : left operand must be l-value
getnamed.c(34) : error C2146: syntax error : missing  ;  before identifier  file
_perms 
getnamed.c(34) : error C2065:  file_perms  : undeclared identifier
getnamed.c(34) : error C2109: subscript requires array or pointer type

有人能帮助我理解为什么文件_perms会被标记为未申报标识符吗? 虽然文件已被宣布为结构?

谢谢你的帮助

最佳回答

你应该

struct file_perms *fp = new file_perms[aclSize.AceCount];

或者在起始时创建类型 :

typedef struct file_perms {
    char user_domain[2050];
    unsigned long user_mask;
}file_perm;

以后你就可以像

file_perms *fp;
fp = (file_perms*)malloc(aclSize.AceCount * sizeof(file_perms));

BTW : 运算符 < 强 > new 是 c++ 语法, 不是纯 C, 您很可能试图将 C++ 代码编译为 C

问题回答

因为你正在将代码编译为 C 代码。 它是 C++ 。

如果您想将其编译为 C, 请尝试 :

typedef struct file_perms_ {
    char user_domain[2050];
    unsigned long user_mask;
} file_perms;

变动 变动

struct file_perms{ 
    char user_domain[2050]; 
    unsigned long user_mask; 
}; 

这将解决您的问题 :

struct{ 
    char user_domain[2050]; 
    unsigned long user_mask; 
}file_perms; 




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签