Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Fucking GCC warnings

Name: Anonymous 2010-11-12 13:54

request for implicit conversion from ‘void *’ to ‘struct keys *’ not permitted in C++

keys = mmap(0, sizeof(struct keys), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

First: C99 code (-x c -std=c99).
Second: what is going on?

Name: Anonymous 2010-11-12 14:26

Are you compiling a .c file?  Are you using g++ to compile instead of gcc?  Also, you're an idiot if you can't figure out whats going on here.

Name: Anonymous 2010-11-12 14:46

prease2lernC++, ``Faggot''

Name: Anonymous 2010-11-12 15:50

>>1

keys = (struct keys)mmap(0, sizeof(struct keys), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);


why are you using sepples?

Name: Anonymous 2010-11-12 16:32

>>4
That's a dumb cast to be suggesting for multiple reasons, not the least of which is its complete uselessness.

Name: Anonymous 2010-11-12 16:56

>>5
stop using sepples then

Name: Anonymous 2010-11-12 17:37

>>6
I'm neither >>1 or a Shittles user. But as a See user you surely recognize that a cast like that is stupid.

Name: Anonymous 2010-11-12 20:28

OP here.

>>2
No; No; Probably yes. Teach me.

>>3
iLernC99

>>4
I am not.

>>7
Please tell me what is going on.

Name: Anonymous 2010-11-12 21:32

>>8
We can't read minds. Post more details, like your CFLAGS and a reduced test case isolating the relevant code.

Name: Anonymous 2010-11-12 21:55

>>8
try programming with all void types.

so like

void main(void argc,void **argv)
{
    void i = 0;
    void string = "Hello World";
    printf("%s!!!!!!",string);
    return i;
}

Name: Anonymous 2010-11-12 23:23

>>10
try programming with all void pointer types.

so like


void *main(void *argc, void ***argv) {
    void *i = malloc(sizeof(int));
    *i = 0;
    void *string = "Hello World";
    printf("%s!!!!!!",string);
    return i;
}

Name: Anonymous 2010-11-13 1:39

>>11
sizeof(int) != sizeof(void*) in many cases, making the retarded assumption that int and void* can be interchanged not just retarded, but often wrong.

Name: Anonymous 2010-11-13 5:12

Eleven replies and no one has fixed the OPs problem yet. The collective skill of /prog/ truly has degraded to a dismal and disappointing low point. You should all be ashamed.

>>4 got pretty close, but he was casting to the struct type, not the pointer to struct type required (mmap returns void*).


keys = (struct keys *)mmap(0, sizeof(struct keys), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);


It doesn't matter if it's C or C++ here, you have to do that cast, especially if you compile with default or elevated warnings in GCC like you should be.

Don't fault the compiler or language for your own stupidity.

Name: Anonymous 2010-11-13 5:18

>>13
ACtually, to clarify, it's not a good practice to name a variable the same as it's type.

struct keys *k;
k = (struct keys *)mmap(0, sizeof(struct keys), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);


That should compile without warning just fine.

Name: Anonymous 2010-11-13 5:57

>>13
Casting a void* when assigning it to another pointer type is worse than useless in C. That cast does nothing but add clutter and possibly hide warnings.

Name: Anonymous 2010-11-13 6:30

>>9

OP, again. There was a typo there...

gcc -x c -std=c99 -Os -g0 -pedantic -Wall -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wsync-nand -Wunused-parameter -Wunknown-pragmas -fstrict-aliasing -fstrict-overflow -Wstrict-overflow=5 -Wfloat-equal -Wtraditional -Wtraditional-conversion -Wdeclaration-after-statement -Wundef -Wbad-function-cast -Wdeclaration-after-statement -Wshadow -Wunsafe-loop-optimizations -Wpointer-arith -Wbad-function-cast -Wc++-compat -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wnormalized=nfkc -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wlong-long -Wvla -Wdisabled-optimization -Wstack-protector -lgmp -lrt -lm -fstack-protector-all -pipe program.c -o program


struct key {
 char *block[SIZE];
};

struct key *keys;

fd = shm_open("/shit", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);

 if (fd == -1)
 {
  perror("/shit");
  return EXIT_FAILURE;
 }

 if (ftruncate(fd, sizeof(struct key)) == -1)
 {
  perror("/shit");
  return EXIT_FAILURE;
 }

 keys = mmap(0, sizeof(struct key), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

 if (keys == MAP_FAILED)
 {
  perror("shm-mmap");
  return EXIT_FAILURE;
 }

Name: Anonymous 2010-11-13 6:32

>>16
-Wc++-compat is causing the warning.

Name: Anonymous 2010-11-13 9:12

>>17

I think that OP is bitching because he is building explicitly with C99 and due to that GCC should be able to suppress this specific warning.

tl;dr: GCC doesn't care

Name: Anonymous 2010-11-13 9:27

>>15
No, you're wrong. If the intent is to cast to a specific type, then you should indeed explicitly perform the cast.

The best software projects are the ones that compile error/warning free with -Wall -Wextra -Werror. Shit with thousands of warnings is not maintainable.

Name: Anonymous 2010-11-13 9:37

>>19
No, you're brain-washed by C++ idiots. Casts from void * are fucking useless.

I maintain a fairly large program, and it probably contains less than 100 casts. Most of those are to work around stupidities with other code that isn't written properly.

Every time I have removed a cast from the code, I have discovered that it was hiding a glaring bug, like casting away a const, passing the resulting pointer to another function where it was saved for later manipulation, which would occasionally crash because it was trying to write to unwritable memory locations. Bullshit like that would never happen if people avoided useless casts of the sort you're recommending.

By the way, my program builds clean with every single GCC warning enabled, save the ridiculously pedantic diagnostics that are prone to giving loads of false positives (such as -Wstrict-overflow).

Name: Anonymous 2010-11-13 9:43

>>19
Compile this program with gcc -std=c99 -pedantic -Wall -Wextra -Werror (or -std=c89) and see how many warnings you get:

#include <stdlib.h>
int main(void) {
  int *p = malloc(sizeof *p);
  free(p);
  return 0;
}


The entire point of introducing void* in the first place was so that we could have a generic pointer type that we didn't have to cast back and forth like we had to do with char* before C89.

Name: Anonymous 2010-11-13 10:14

>>20
I bet you also use -fstrict-aliasing, you flaming ``faggot''.

Name: Anonymous 2010-11-13 12:25

Use LLVM to fix all your problem.

Name: Anonymous 2010-11-13 14:12

>>19
The free software projects that use -Werror are invariably the ones I have to dick around in the source to get it to compile, because the developers didn't happen to test on my platform and/or compiler.

Fuck them, seriously.

Name: Anonymous 2010-11-13 16:04

>>24
What crazy platform are you using?

I agree though, don't enable -Werror by default, because that's just stupid and you never know what sorts of warnings might pop up on other platforms that you haven't anticipated. But, DO encourage other developers to test with -Werror and submit patches to fix warnings and stylistic issues.

Name: Anonymous 2010-11-14 1:04

-fheinous-gnu-extensions

Name: Anonymous 2010-11-14 2:22

-faggotry

Name: Anonymous 2010-11-14 7:46

Name: Anonymous 2010-11-14 10:09

-fuck-off -faggot

Name: Anonymous 2011-02-03 4:11

Don't change these.
Name: Email:
Entire Thread Thread List