To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1689
1688  |  1690
Subject: 
NQC preprocessor behavior - constants evaluated?
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Mon, 16 Aug 2004 01:46:33 GMT
Viewed: 
5299 times
  
   Pardon a basic, low-level question, but I'm trying to minimize memory &
execution time. Does the NQC preprocessor precalculate constant expressions
before the compile pass? For instance:

#define CONST 100
#define HALF  CONST/2

task main()
{
   int x,y;
   x = 3 * HALF;
   y = 10 / 2 * x;
}

When this compiles, will the bytecode have the variable x assigned a single
constant, or will the bytecode actually be doing time (and memory) wasting
things like dividing 100 by 2 (in the second #define), or multipling a constant
by another constant (the assignment statement). And could it take the second
assignment statement and simplify it to a single math operation (5 * x).
Anybody?

--
Brian Davis



Message has 2 Replies:
  Re: NQC preprocessor behavior - constants evaluated?
 
(...) The preprocessor only evaluates expressions if they are used in a conditional preprocessor statement (i.e. #if), otherwise they are simply treated as a series of tokens for the compiler to deal with. However, the compiler does evaluate (...) (20 years ago, 17-Aug-04, to lugnet.robotics.rcx.nqc)
  Re: NQC preprocessor behavior - constants evaluated?
 
Code listing of Untitled1: *** Var 47 = x *** Var 46 = y *** Task 0 = main 000 pwr ABC, 7 13 07 02 07 004 dir ABC, Fwd e1 87 006 setv var[47], 150 14 2f 02 96 00 011 setv var[46], 5 14 2e 02 05 00 016 mulv var[46], var[47] 54 2e 00 2f 00 Total size: (...) (20 years ago, 18-Aug-04, to lugnet.robotics.rcx.nqc)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR