Hi, I'm trying to convert a void pointer to a struct pointer.. that's seems very easy but my compiler give me error.

Thanks.

/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp||In function ‘error_t parse_opt(int, char*, argp_state*)’:|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|50|error: expected primary-expression before ‘)’ token|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|50|error: expected ‘;’ before ‘null_pointer’|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|48|warning: unused variable ‘null_pointer’|
||=== Build finished: 2 errors, 1 warnings ===|

static error_t parse_opt(int key, char *arg, struct argp_state* state)
{
        void* null_pointer = state->input;
[B]	struct arguments *arguments;
	arguments = (arguments*) null_pointer;[/B]

	switch (key)
	{
		case 'v':
			arguments->verbose = 1;
			break;

		case 'i':
			arguments->infile = arg;
			break;

		case 'o':
			arguments->outfile = arg;
			break;

		case ARGP_KEY_ARG:
			if (state->arg_num >= 1)
			{
				argp_usage(state);
			}

			arguments->args[state->arg_num] = arg;
			break;

		case ARGP_KEY_END:
			if (state->arg_num < 1)
			{
				argp_usage(state);
			}
			break;

		default:
			return ARGP_ERR_UNKNOWN;
	}

	return 0;
}

Hi, I'm trying to convert a void pointer to a struct pointer.. that's seems very easy but my compiler give me error.

Thanks.

/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp||In function ‘error_t parse_opt(int, char*, argp_state*)’:|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|50|error: expected primary-expression before ‘)’ token|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|50|error: expected ‘;’ before ‘null_pointer’|
/home/subi/Personal/Projects/LinkedListUserInfo/main.cpp|48|warning: unused variable ‘null_pointer’|
||=== Build finished: 2 errors, 1 warnings ===|

static error_t parse_opt(int key, char *arg, struct argp_state* state)
{
        void* null_pointer = state->input;
[B]	struct arguments *arguments;
	arguments = (arguments*) null_pointer;[/B]

	switch (key)
	{
		case 'v':
			arguments->verbose = 1;
			break;

		case 'i':
			arguments->infile = arg;
			break;

		case 'o':
			arguments->outfile = arg;
			break;

		case ARGP_KEY_ARG:
			if (state->arg_num >= 1)
			{
				argp_usage(state);
			}

			arguments->args[state->arg_num] = arg;
			break;

		case ARGP_KEY_END:
			if (state->arg_num < 1)
			{
				argp_usage(state);
			}
			break;

		default:
			return ARGP_ERR_UNKNOWN;
	}

	return 0;
}

why not simply set the pointer directly?

static error_t parse_opt(int key, char *arg, struct argp_state* state)
{
[B]	struct arguments *arguments = (arguments*)state->input;[/B]

I missed the word struct in the cast from the void pointer. i don't know why the compiler need it, but it compiled.

struct arguments* arguments = (struct arguments*) state->input;

Thanks.

This question has already been answered. Start a new discussion instead.