How to declare an unsigned 16-bit variable in Prop GCC?

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 22,579
edited 2020-03-18 - 02:46:38 in Propeller 1
I have the following table in my C code:
short _sigmoid[257] = {
      0,   17,   34,   51,   70,   89,  109,  129,  151,  173,  196,  220,  246,  272,  299,  327,
    357,  387,  419,  452,  486,  522,  559,  598,  638,  680,  723,  768,  815,  864,  914,  967,
   1022, 1078, 1137, 1199, 1262, 1328, 1397, 1468, 1543, 1619, 1699, 1782, 1868, 1958, 2050, 2147,
   2246, 2350, 2457, 2569, 2685, 2804, 2929, 3057, 3191, 3329, 3473, 3621, 3775, 3934, 4099, 4270,
   4447, 4630, 4819, 5014, 5217, 5426, 5642, 5865, 6096, 6334, 6580, 6834, 7096, 7366, 7645, 7932,
   8228, 8532, 8846, 9169, 9501, 9843,10194,10555,10926,11307,11697,12098,12509,12930,13361,13802,
  14254,14716,15188,15670,16162,16664,17176,17697,18228,18769,19319,19877,20445,21021,21605,22197,
  22797,23404,24018,24638,25264,25896,26534,27176,27823,28473,29127,29783,30442,31103,31765,32428,
  33091,33754,34416,35077,35736,36393,37047,37697,38343,38986,39623,40255,40882,41502,42116,42723,
  43322,43914,44499,45074,45642,46201,46750,47291,47822,48344,48856,49358,49850,50332,50804,51265,
  51717,52158,52590,53011,53421,53822,54213,54593,54964,55325,55676,56018,56350,56673,56987,57292,
  57588,57875,58153,58423,58685,58939,59185,59423,59654,59877,60094,60303,60505,60701,60890,61073,
  61249,61420,61585,61744,61898,62047,62190,62328,62462,62591,62715,62835,62951,63062,63169,63273,
  63373,63469,63562,63651,63737,63820,63900,63977,64051,64122,64191,64257,64321,64382,64441,64498,
  64552,64605,64656,64704,64751,64796,64840,64881,64922,64960,64997,65033,65067,65100,65132,65163,
  65192,65221,65248,65274,65299,65323,65346,65369,65390,65411,65431,65450,65468,65486,65503,65519,
  65535
};

Even though the compiler accepts positive constants like 65535, it treats them as negative numbers later in my program. I want them to be treated as unsigned. How do I do it? (Prop GCC does not recognize ushort.)

Thanks,
-Phil

Comments

  • dgatelydgately Posts: 1,207
    edited 2020-03-18 - 15:42:19
    EDIT:
    uint16_t _sigmoid[257] = {...
    
    OR
    
    unsigned short _sigmoid[257] = {...
    
    OR
    
    unsigned short int _sigmoid[257] = {...
    

    ?
  • TorTor Posts: 1,994
    "unsigned" (not "Unsigned"), but yes, as dgately says. I usually use just "unsigned short", or the "modern" way, "uint16_t"
  • If you want that spicy Spin flavor you can also do
    typedef uint16_t word;
    
  • Thanks, guys! I'll give uint16_t a try. (What's the _t for?)

    -Phil
  • the _t stands for "type". Some people like to suffix every symbol. In this case, it is also so that programs written before the introduction of stdint.h (which defines all these good types) are less likely to break when including it.
Sign In or Register to comment.