From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bc745b8412f53f25 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-01 03:37:25 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!martinkl.dialup.fu-berlin.DE!not-for-mail From: Martin Klaiber Newsgroups: comp.lang.ada Subject: Re: Error-names. Date: Mon, 1 Mar 2004 12:20:37 +0100 Organization: Freie Universitaet Berlin Sender: Martin Klaiber Message-ID: <5tibh1-m92.ln1@martinkl.dialup.fu-berlin.de> References: NNTP-Posting-Host: martinkl.dialup.fu-berlin.de (130.133.237.205) X-Trace: news.uni-berlin.de 1078141043 57316767 F 130.133.237.205 (10182) X-Orig-Path: not-for-mail User-Agent: tin/1.5.12-20020427 ("Sugar") (UNIX) (Linux/2.4.24 (i586)) Xref: archiver1.google.com comp.lang.ada:5970 Date: 2004-03-01T12:20:37+01:00 List-Id: tmoran@acm.org wrote: > It would not be hard to leave out, or have multiple uses of, an error > code, as in: > Constraint_Error_Code : constant Exception_Codes := -10; > Program_Error_Code : constant Exception_Codes := -9; > Storage_Error_Code : constant Exception_Codes := -9; > Status_Error_Code : constant Exception_Codes := -7; > My_Special_Error_Code : constant Exception_Codes := -5; > ... > Similarly, a new exception might be added, but someone forgets to > add it to the if-elsif list. > With the if-elsif style you can only hope that neither of those happens. > But if you do > Coded_Exception_List : constant array(Exception_Codes) > of Ada.Exceptions.Exception_ID > := (Constraint_Error_Code => Constraint_Error'Identity, > Program_Error_Code => Program_Error'Identity, > Storage_Error_Code => Storage_Error'Identity, > IO_Status_Error_Code => Ada.IO_Exceptions.Status_Error'Identity, > My_Special_Error_Code => My_Special_Exception'Identity, > ... > then the compiler will warn you if two of your error codes are the > same, or if you've left any out in the Exception_Codes range. This is right but how can I export the constants then? At the moment I use in the spec-file: -- No error: No_Error_Code : constant C_Integer := 0; pragma export (C, No_Error_Code, "no_error_code"); -- Fallback: General_Error_Code : constant C_Integer := -1; pragma export (C, General_Error_Code, "general_error_code"); and so on. The reason is that I want the C-programmer to use the constants-names instead of the values, because I can't guarantee that the values will not change in the future. BTW: does someone know why these constants are not recognized by the C-program as constants? They are declared as constants and in the C header-file I put: /* error-codes */ extern const int no_error_code; extern const int general_error_code; ... But if I want to use it in a switch-command like that: int year; ... for (year = 2003; year <= 2005; ++year) { switch (set_year (year)) { case no_error_code : set_lzz (1); ... the compiler says: test_c.c:20: case label does not reduce to an integer constant Is my exporting wrong? Or is this a C-problem? When I use "case 0" instead of "case no_error_code" it works ok, but this is what I want to avoid. Thanks, Martin