User Profile

Collapse

Profile Sidebar

Collapse
hschew00
hschew00
Last Activity: Dec 15 '10, 08:27 PM
Joined: Aug 29 '09
Location: Fairfield, NJ
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • hschew00
    replied to const pointer to a const string
    in C
    Don,
    Using the suggested #define is fine, as indicated by my first example, or the equivalent passing the constant address
    Code:
    const char  UNIT1[] = "kPa";
    const char  UNIT2[] = "ft";
    I just don't understand why I can't pass the constant pointer to a constant to the structure.
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to const pointer to a const string
    in C
    One more thing with the suggestion that you proposed, not only it did not compiled with UNIT1 and UNIT2 as initializers, it did compiled correctly with string literals as initializers "kPa" and "ft", and the compiled hex file from Keil compiler is the same for both
    char* unit;
    or
    const char* unit;
    within PARAMETER STRUCTURE. Beat me.
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to const pointer to a const string
    in C
    Don, at first I followed the same logic as you stated, however, the Visual C compiler could not compile it successfully, same as the Keil compiler that I used. The first example can be compiled by both, and the memory buffer on the hardware confirmed the intended data stored at the right location. Try it on the VC6 and you know what I meant.
    See more | Go to post

    Leave a comment:


  • hschew00
    started a topic const pointer to a const string
    in C

    const pointer to a const string

    I have the following:

    Code:
    float var_1, var_2;
    const char* const UNIT1 = "kPa";
    const char* const UNIT2 = "ft";
    
    struct PARAMETER 
    {
    	float*   value;
    	int      par_type;
    	int      max_index;
    	float    init;
    	float    min;
    	float    max;
    	float    step;
    	char*    unit;
    };
    
    const struct PARAMETER params[]
    ...
    See more | Go to post

  • hschew00
    replied to assigning floating literal to void*
    in C
    @Oralloy,
    Your solution is way above me. After googling around, realized that ANSI C does not support static initialization for Union, that is a shame. May be I have to give up this approach totally. Thanks to you and Don anyway.
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to assigning floating literal to void*
    in C
    Don,
    I think Visual C 6.0 doesn't like the initialization of union part. i.e.,{.iv = {10, 0, 100, 1}}, same with my Keil Compiler. How would you initialize a static object of a union of different structure types in ANSI C?
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to assigning floating literal to void*
    in C
    @Oralloy,
    Your solution of different struct for different data type can be another option too. The original structure used in my application is 48bytes instead of 16bytes, moreover, the controller that I used has 16k of RAM only.
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to assigning floating literal to void*
    in C
    Thanks Donbock. That looks like it may work. I will try that out and post the result. You mentioned C99 has to be used instead of ANSI C (C90??), I may have a problem with the compiler that I got from Keil. I will check that out.
    See more | Go to post

    Leave a comment:


  • hschew00
    replied to assigning floating literal to void*
    in C
    @Oralloy
    I realized this is the answer I will get after I posted this, and I think my original intention is not cleared to everybody. Below is a sample that what I want to achieve in embedded ARM7:

    Code:
    float fval;
    int ival;
    char sval[100];
     
    const STR_INIT[]="ggwegweggegggwgwgw";
    enum
    {
     DAT_BYTE=0,
     DAT_INT,
     DAT_FLOAT,
     DAT_STRING
    };
     
    struct
    ...
    See more | Go to post
    Last edited by Niheel; Sep 9 '10, 03:06 AM. Reason: please use code tags to display code

    Leave a comment:


  • hschew00
    started a topic assigning floating literal to void*
    in C

    assigning floating literal to void*

    if I have the following:
    void *x;
    const char str[]="abcdefghijklm n";

    I can assign x=0x12345678;
    I can assign x=str;

    but how can I assign a float literal to x such that the content of x is an IEEE754 format of this literal floating point?
    See more | Go to post

  • hschew00
    replied to using define label in a string
    in C
    Jos,
    Thanks for the quick reply. However, although it works, can you explain to me how it works in preprocessor? Intuitively I thought the above 2 defines is equivalent to sth like this
    #define concat(a,b) a###b

    Of course the above didn't work.
    See more | Go to post

    Leave a comment:


  • hschew00
    started a topic using define label in a string
    in C

    using define label in a string

    Is there a way to declare a string where inside the string, a predefined label is included? I.e.,

    #define MY_CODE 0x1000
    char str[]="Here is MY_CODE"; //will not work I know

    Any way to get around this instead of hard-coding it?
    See more | Go to post
No activity results to display
Show More
Working...