Title: | DECC |
Notice: | General DEC C discussions |
Moderator: | TLE::D_SMITH N TE |
Created: | Fri Nov 13 1992 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 2212 |
Total number of notes: | 11045 |
Can you tell me why a simple descriptor fails under decc extensions. This one compiles under vaxc. the error message is as follows. $DESCRIPTOR(message_dsc,msg); ...^ %CC-W-NEEDCONSTEXT, In the initializer for message_dsc.dsc$a_pointer, "msg" is not constant, but occurs in a context that requires a constant expression. This is an extension of the language. At line number 17 in DISK12:[D_BUTLER]SAVAGE.C;9. #include <descrip.h> #include <ssdef.h> #include <stdio.h> /******************************************************************** *** Print a message to the console operator. ********************************************************************/ void dl_printop(msg) char *msg; { struct { short status, count; int dev_info; } iosb; struct dsc$descriptor_s term_dsc; int status=0, flags=0, reqid=0; $DESCRIPTOR(message_dsc,msg); term_dsc.dsc$w_length = 4; term_dsc.dsc$b_dtype = DSC$K_DTYPE_T; term_dsc.dsc$b_class = DSC$K_CLASS_S; term_dsc.dsc$a_pointer = "OPA0"; /* flags=BRK$M_SCREEN | BRK$M_BOTTOM; reqid=BRK$C_URGENT; status=sys$brkthruw(0,&message_dsc,&term_dsc,BRK$C_DEVICE,&iosb,0, flags,reqid,0,0,0); */ } /* dl_printop */
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
2158.1 | SPECXN::DERAMO | Dan D'Eramo | Tue Apr 22 1997 17:15 | 55 | |
ANSI C requires (X3.159-1989 section 3.5.7 page 72) All the expressions in an initializer for an object that has static storage duration or in an initializer list for an object that has aggregate or union type shall be constant expressions. The $DESCRIPTOR macro is defined as follows: #define $DESCRIPTOR(name,string) \ struct dsc$descriptor_s name = \ { sizeof(string)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, string } So these char buffer[81]; $DESCRIPTOR(dsc1, "text"); $DESCRIPTOR(dsc2, buffer); expand to char buffer[81]; struct dsc$descriptor_s dsc1 = { sizeof("text")-1, 14, 1, "text" }; struct dsc$descriptor_s dsc2 = { sizeof(buffer)-1, 14, 1, buffer }; I.e., the expansion of $DESCRIPTOR includes an initializer list for an object that has aggregate or union type. So the expressions in the initializer lists must be constant expressions. This is true of all four expressions in the first list, and it is true for the first three expressions of the second list. But it is not necessarily true for the last expression in the second list unless ``buffer'' has been declared with static storage duration. Here ``buffer'' works out to be &buffer[0] and if the array ``buffer'' does not have static storage duration then its address need not be considered constant. You can get the same effect with struct X { int a; int b; }; void f(int n) { int i = n; /* okay */ struct X x = { 1, n }; /* extension to ANSI C */ } DEC C will allow it but it is an extension to ANSI C. Dan | |||||
2158.2 | Example in your source | DECCXL::WIBECAN | That's the way it is, in Engineering! | Tue Apr 22 1997 17:26 | 22 |
You have a good example of a successful way to use the descriptor structure right in the same source: struct dsc$descriptor_s term_dsc; term_dsc.dsc$w_length = 4; term_dsc.dsc$b_dtype = DSC$K_DTYPE_T; term_dsc.dsc$b_class = DSC$K_CLASS_S; term_dsc.dsc$a_pointer = "OPA0"; By example, you could then use: struct dsc$descriptor_s message_dsc; message_dsc.dsc$w_length = strlen(msg); message_dsc.dsc$b_dtype = DSC$K_DTYPE_T; message_dsc.dsc$b_class = DSC$K_CLASS_S; message_dsc.dsc$a_pointer = msg; This should work for you. Brian |