From: Peter S. <pe...@st...> - 2010-02-01 04:03:49
|
Francesco wrote: > I'm not sure to understand why libusb uses: > #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) > [] /* valid C99 code */ > #else > [0] /* non-standard, but usually working code */ > #endif > ; > instead of a simple pointer declaration... As was mentioned, array entry 0 is stored where this struct member starts, followed by entry 1, and so on. It's not a pointer, it's an array - but with unknown length. All places where the struct size needs to be known must somehow find out how many array entries are included in it - sizeof() and other compiler helpers do not work. > anyway I fear that the fact MSVC is unable to generate the > copy-ctor or the copy-assignment operators may create some > very-hard-to-detect bugs (since you can still write "t1 = t2;" > where t1,t2 are libusb_transfer structs!)... That will not work. You must manually handle all of the array entries; first alloc enough memory for t1 so that there is room, then possibly you can use t1=t2; but you must manually copy the array entries anyway, so you might as well just copy the entire struct instead and have less code. > PS: btw setting /W4 makes the compiler spit out lots of other warnings > and some of them could be pointing to real problems; e.g. > > warning C4305: 'type cast' : truncation from 'list_head *' to 'unsigned long' > warning C4306: 'type cast' : conversion from 'int' to 'HANDLE' of greater size > warning C4706: assignment within conditional expression Interesting! Can you show the places in the code that triggers these? //Peter |