A
andreyvul
gcc 3.4 (mingw) says error: invalid operands to binary + when I try to
to pointer arithmetic to calculate offset of a certain element.
It compiles without errors or warnings in MSVC.
Any clue why?
code (fully compilable snippet):
/* Disable MSVC W C4996 */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
#ifndef _MSC_VER
#include <stdint.h>
#else /* _MSC_VER */
typedef unsigned __int32 uint32_t;
#endif /* _MSC_VER */
/*
* Sub-cheat (#)
*/
typedef struct sub_s {
/* Sub-cheat title */
char *label;
/* An array of 32-bit numbers containing an address or a value */
uint32_t *data;
/* The number of addresses and values */
size_t n_data;
} sub_t;
/*
* Main cheat (@)
*/
typedef struct cheat_s {
/* Cheat title */
char *label;
/* Array of sub-cheat(s) */
sub_t *sub;
/* The number of sub-cheat(s) */
size_t n_subs;
} cheat_t;
/* Global pointer to (main) cheats */
cheat_t *cheat;
/* The number of (main) cheats */
size_t n_cheats;
void foo() {
printf("debug: cheat[n_cheats - 1] @ %p\n", cheat + (cheat_t *)
(n_cheats - 1));
}
to pointer arithmetic to calculate offset of a certain element.
It compiles without errors or warnings in MSVC.
Any clue why?
code (fully compilable snippet):
/* Disable MSVC W C4996 */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
#ifndef _MSC_VER
#include <stdint.h>
#else /* _MSC_VER */
typedef unsigned __int32 uint32_t;
#endif /* _MSC_VER */
/*
* Sub-cheat (#)
*/
typedef struct sub_s {
/* Sub-cheat title */
char *label;
/* An array of 32-bit numbers containing an address or a value */
uint32_t *data;
/* The number of addresses and values */
size_t n_data;
} sub_t;
/*
* Main cheat (@)
*/
typedef struct cheat_s {
/* Cheat title */
char *label;
/* Array of sub-cheat(s) */
sub_t *sub;
/* The number of sub-cheat(s) */
size_t n_subs;
} cheat_t;
/* Global pointer to (main) cheats */
cheat_t *cheat;
/* The number of (main) cheats */
size_t n_cheats;
void foo() {
printf("debug: cheat[n_cheats - 1] @ %p\n", cheat + (cheat_t *)
(n_cheats - 1));
}