C Code "Integral Type Required" Error - Page 1
Forum section: electronics / beginners

author: t1d
author_rank: Super Contributor
timestamp: April 02, 2018, 03:26:17 am
content: RE:MPLab X v4.15XC8 v1.45PIC12F683I am new to coding.Issue: I am receiving an “Integral Type Required” error, for each of the three lines of code, below, highlighted in red.What is tripping me up is:1) The integral types have been declared and2) I do not see that the effected code includes, or creates, a variable without a declaration.3) I do not see an error, in the line preceding the first error.This is not the complete code. It is only the effected portion.The point of this portion is to test a value and illuminate one of three LEDs, based on the test’s result.I have done my hours of due diligence, with study and research.An example of the corrective code would be helpful, as opposed to just making a statement, as to the needed correction.Thank you for your help and support.// Declarationsfloat probe = 0; // Storage for Probe valuefloat avg_reading = 0; // Storage for average Probe readingsfloat avg_reading_sam ; // Storage array for DUT logic samplesfloat logic_vref ; // Storage array for DUT logic voltage test levelsint x = 0; // Incremental Valuefloat avg_vref = 0; // Average working voltage referenceint count = 0; // Incremental Valueunsigned char select = 0; // 1 is CMOS selected; otherwise 2 for TTLunsigned char tim_ct = 0;// Storage for time countfloat read_adc();void main(void){Unaffected code removedBegin herewhile (3){// Operationswhile (4){if ((select == 2) && (ANS3 > 0))for (count = 1; count < 5; count++){avg_reading_sam  = (9.1*(read_adc())); // Multiplies reading to actual voltage value toemphasis difference between probed and reference values, to aid analysis. This actual voltage value be output to a laptop, in future revisions. Set to actual, tested resistor value.__delay_ms (100); // Spread sampling over timeif (avg_reading_sam  == 0) count--; // Retest failed readsavg_reading = (avg_reading + avg_reading_sam ); // Sums DUT logic voltage test values}avg_reading = ((avg_reading)/5); // Averages DUT logic voltage test valuesif (avg_reading << (avg_vref * 0.33)) GPIObits.GP0 = 1; // Low Level Stateif (((avg_reading == (avg_vref * 0.33)) || (avg_reading >> (avg_vref * 0.33))) && ((avg_reading << (avg_vref * 0.67)) || (avg_reading == (avg_vref * 0.67)))) GPIObits.GP1 = 1; // Indeterminate Level Stateif (avg_reading >> (avg_vref * 0.67)) GPIObits.GP2 = 1; // High Level State__delay_ms (1000);avg_reading = 0; // Clears avg_reading valuecount = 0; // Clears count valuereturn;}

author: Tomorokoshi
author_rank: Super Contributor
timestamp: April 02, 2018, 03:40:05 am
content: Quote from: t1d on April 02, 2018, 03:26:17 amOperations such asavg_reading << (avg_vref * 0.67)are taking a float (avg_vref), multiplying it by another float, which of course returns a float.However, the "<<" operation shifts by an integral number of bits. Shifting by a non-integral number is something the compiler isn't making assumptions about, so it's declaring an error.While it may be the case that something like:avg_reading << ((int) (avg_vref * 0.67))would alleviate the issue, it will likely evaluate to only the integral part, instead of rounding. You will need to analyze the behavior of the code to determine the exact method of how to deal with the fractional part of the value to shift by.Perhaps calculate an intermediate variable of type int to evaluate the number of bits to shift, and use that with the << (and similar) operators instead.

author: t1d
author_rank: Super Contributor
timestamp: April 02, 2018, 03:48:35 am
content: Thank you so much for your help!I do not think that I am intending to execute a shift. I am intending to test if the value is:First line - Less than 0.33Second line - Between 0.33 and 2.2Third line - Above 2.2So, it seems I have a syntax error. What structure do I need, to accomplish the comparison?Thanks!

author: t1d
author_rank: Super Contributor
timestamp: April 02, 2018, 04:12:11 am
content: Okay, let's see, if I am getting my head around this, a little bit.Because I am doing a mathematical operation to a float, the compiler needs to know what type of variable output I want. The consideration for making that decision is what level of precision that I want. I know that I want this result to be float, also.So, I tried this:if (avg_reading << (float) (avg_vref * 0.33)) GPIObits.GP0 = 1; // Low Level StateThe compiler still complains that the integral type is required...

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: April 02, 2018, 04:31:37 am
content: Code:if (avg_reading < (float) (avg_vref * 0.33)) GPIObits.GP0 = 1; // Low Level State

author: ejeffrey
author_rank: Super Contributor
timestamp: April 02, 2018, 04:38:31 am
content: The comparison operators are '<' and '>', not '<<' and '>>' which are bit shift operators.equality comparison is '==' because '=' is used for assignment, but that pattern isn't continued to the less-than / greater-than operators.

author: t1d
author_rank: Super Contributor
timestamp: April 02, 2018, 04:40:59 am
content: Excellent! Thanks guys, that clears it up. I am ever so grateful.

author: westfw
author_rank: Super Contributor
timestamp: April 02, 2018, 05:42:21 am
content: QuoteI doubt that the PIC12f683 will be very happy about being told to do floating point calculations...