Structure problem - Size not known??? 
Author Message
 Structure problem - Size not known???

The following is an example program for a problem structure. It
refuses to compile saying "Size not known."

Anyone know why?

#include <sys/types.h>

typedef unsigned long   Ulong;
typedef unsigned int    Uint;
typedef unsigned short  Ushort;
typedef unsigned char   Uchar;

typedef unsigned char   Ucbit;

struct cd_mode_page_2A {                /* CD Cap / mech status */
        u_char  p_len;                  /* 0x14 = 20 Bytes */
        Ucbit   cd_r_read       : 1;    /* Reads CD-R  media
*/
        Ucbit   cd_rw_read      : 1;    /* Reads CD-RW media
*/
        Ucbit   method2         : 1;    /* Reads fixed packet method2
media  */
        Ucbit   dvd_rom_read    : 1;    /* Reads DVD ROM media
*/
        Ucbit   dvd_r_read      : 1;    /* Reads DVD-R media
*/
        Ucbit   dvd_ram_read    : 1;    /* Reads DVD-RAM media
*/
        Ucbit   res_2_67        : 2;    /* Reserved
*/
        Ucbit   cd_r_write      : 1;    /* Supports writing CD-R
media        */
        Ucbit   cd_rw_write     : 1;    /* Supports writing CD-RW
media        */
        Ucbit   test_write      : 1;    /* Supports emulation write
*/
        Ucbit   res_3_3         : 1;    /* Reserved
*/
        Ucbit   dvd_r_write     : 1;    /* Supports writing DVD-R
media        */
        Ucbit   dvd_ram_write   : 1;    /* Supports writing DVD-RAM
media    */
        Ucbit   res_3_67        : 2;    /* Reserved
*/
        Ucbit   audio_play      : 1;    /* Supports Audio play
operation     */
        Ucbit   composite       : 1;    /* Deliveres composite A/V
stream    */
        Ucbit   digital_port_2  : 1;    /* Supports digital output on
port 2 */
        Ucbit   digital_port_1  : 1;    /* Supports digital output on
port 1 */
        Ucbit   mode_2_form_1   : 1;    /* Reads Mode-2 form 1 media
(XA)    */
        Ucbit   mode_2_form_2   : 1;    /* Reads Mode-2 form 2 media
*/
        Ucbit   multi_session   : 1;    /* Reads multi-session media
*/
        Ucbit   res_4           : 1;    /* Reserved
*/
        Ucbit   cd_da_supported : 1;    /* Reads audio data with READ
CD cmd */
        Ucbit   cd_da_accurate  : 1;    /* READ CD data stream is
accurate   */
        Ucbit   rw_supported    : 1;    /* Reads R-W sub channel
information */
        Ucbit   rw_deint_corr   : 1;    /* Reads de-interleved R-W sub
chan  */
        Ucbit   c2_pointers     : 1;    /* Supports C2 error pointers
*/
        Ucbit   ISRC            : 1;    /* Reads ISRC information
*/
        Ucbit   UPC             : 1;    /* Reads media catalog number
(UPC)  */
        Ucbit   read_bar_code   : 1;    /* Supports reading bar codes
*/
        Ucbit   lock            : 1;    /* PREVENT/ALLOW may lock
media        */
        Ucbit   lock_state      : 1;    /* Lock state 0=unlocked
1=locked    */
        Ucbit   prevent_jumper  : 1;    /* State of prev/allow jumper
0=pres */
        Ucbit   eject           : 1;    /* Ejects disc/cartr with STOP
LoEj  */
        Ucbit   res_6_4         : 1;    /* Reserved
*/
        Ucbit   loading_type    : 3;    /* Loading mechanism type
*/
        Ucbit   sep_chan_vol    : 1;    /* Vol controls each channel
separat */
        Ucbit   sep_chan_mute   : 1;    /* Mute controls each channel
separat*/
        Ucbit   disk_present_rep: 1;    /* Changer supports disk
present rep */
        Ucbit   sw_slot_sel     : 1;    /* Load empty slot in changer
*/
        Ucbit   res_7           : 4;    /* Reserved
*/
        u_char  max_read_speed[2];      /* Max. read speed in KB/s
*/
        u_char  num_vol_levels[2];      /* # of supported volume
levels       */
        u_char  buffer_size[2];         /* Buffer size for the data in
KB    */
        u_char  cur_read_speed[2];      /* Current read speed in KB/s
*/
        u_char  res_16;                 /* Reserved
*/
        Ucbit   res_17_0        : 1;    /* Reserved
*/
        Ucbit   BCK             : 1;    /* Data valid on falling edge
of BCK */
        Ucbit   RCK             : 1;    /* Set: HIGH high LRCK=left
channel  */
        Ucbit   LSBF            : 1;    /* Set: LSB first Clear: MSB
first   */
        Ucbit   length          : 2;    /* 0=32BCKs 1=16BCKs 2=24BCKs
3=24I2c*/
        Ucbit   res_17          : 2;    /* Reserved
*/
        u_char  max_write_speed[2];     /* Max. write speed supported
in KB/s*/
        u_char  cur_write_speed[2];     /* Current write speed in KB/s
*/

Quote:
};

void main()
{
   struct cd_mode_page_2a a;
   struct cd_mode_page_2a *b;
   unsigned char c[255];
   b=(struct cd_mode_page_2a *)c;
   b->max_write_speed[0]=0;
   return;

Quote:
}

--
Remove the vegetable in my email address to reply sucessfully.
http://www.*-*-*.com/ (remove the vegetable)


Tue, 30 Jan 2001 03:00:00 GMT  
 Structure problem - Size not known???


Quote:
>The following is an example program for a problem structure. It
>refuses to compile saying "Size not known."

>Anyone know why?

>#include <sys/types.h>

This is a non-standard header.

Quote:
>typedef unsigned long   Ulong;
>typedef unsigned int    Uint;
>typedef unsigned short  Ushort;
>typedef unsigned char   Uchar;

>typedef unsigned char   Ucbit;

The *only* types the C language supports for bit-fields are int, signed int
and unsigned int.

Quote:
>struct cd_mode_page_2A {                /* CD Cap / mech status */
>        u_char  p_len;                  /* 0x14 = 20 Bytes */
>        Ucbit   cd_r_read       : 1;    /* Reads CD-R  media

...

Quote:
>void main()

Error: main returns int in C.

Quote:
>{
>   struct cd_mode_page_2a a;
>   struct cd_mode_page_2a *b;

You haven't defined a type ``struct cd_mode_page_2a'', what you have
defined is ``struct cd_mode_page_2A'' (note the last character). As far
as your compiler is concerned these are two disttinct types and the first
one is incomplete i.e. it has no specified member list i.e. its size is
not known.

Quote:
>   unsigned char c[255];
>   b=(struct cd_mode_page_2a *)c;

(Note the structure tag name is wrong here too)

This is dangerous, as the fact that you had to use a pointer cast should
indicate. c is not guaranteed to be appropriately aligned to hold a
struct cd_mode_page_2A, even assuming it is large enough. Either define
c as a struct cd_mode_page_2A, or if for some reason you really want
exactly 255 bytes use

    if ((b = malloc(255)) == NULL) {
        /* Deal with allocation failure */
    }

(remember to #include <stdlib.h> for malloc)

malloc() is guaranteed to allocate a block of memory appropriate aligned
for any type of object.

Quote:
>   b->max_write_speed[0]=0;
>   return;

    free(b);    /* if malloc was used */

    return 0;   /* Indicates successful completion of the program */

Quote:
>}

--
-----------------------------------------


-----------------------------------------


Tue, 30 Jan 2001 03:00:00 GMT  
 Structure problem - Size not known???
: The following is an example program for a problem structure. It
: refuses to compile saying "Size not known."

: Anyone know why?

[ snip ]
: typedef unsigned char Ucbit;

: struct cd_mode_page_2A {              /* CD Cap / mech status */
                     ^^^^
[ snip ]
: {
:    struct cd_mode_page_2a a;
                        ^^^^

8-)

Ciao ciao
Andrea
--
"...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and
 the Ugly)."
(by Matt Welsh)



Fri, 02 Feb 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Linux - Error : storage size of var not known

2. How to set Window size when I only know size of client area

3. structure size problem (was Re: HELP)

4. Find size of variable size structure?

5. Problem: Compiler does not know the .Item property

6. dialog size in evc++ dialog editor not the same as size in pixels on device

7. pointers, structures, and God only knows

8. Problem using structures in structures

9. Anyone Know How To Access A Structure?

10. Anybody know the structure of win32 heap?

11. Does anyone know the cemrgc.exe command structure?

12. I want to know size of H323 Protocol source

 

 
Powered by phpBB® Forum Software