Announcement

Collapse
No announcement yet.

Again: C conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Again: C conversion

    Is there any difference between these C notations:
    I mean the meaning of the (non)presence of the decimal point...
    Code:
      Vdd   = edtVdd/10.;
      Vpp   = edtVpp/10;
    ------------------
    Regards,
    Peter
    Regards,
    Peter

  • #2
    As far as I remember "10." assign type for 10 as float,
    and without decimal point it assume LONG-type

    SY,


    ------------------
    -=Alex=-
    -=Alex=-

    Comment


    • #3
      So:
      Code:
      Vdd  = edtVdd/10.; would become Vdd  = edtVdd/10
           and
      Vpp  = edtVpp/10;  would become Vpp  = edtVpp\10

      ------------------
      Regards,
      Peter
      Regards,
      Peter

      Comment


      • #4
        I don't think so.
        \ is dividing different.
        Using a float or integer has impact on the cpu.

        But maybe i'm wrong here.

        ------------------
        http://www.hellobasic.com
        hellobasic

        Comment


        • #5
          Mixed numeric types means some type of conversion is required. If
          mixing float and integer types, the integer types need to be
          converted to float first. PowerBasic handles this automatically
          for you, but if you tag on the decimal point, you ask that
          PowerBasic be sure to store that 10 in float format.

          I would like to say that PowerBasic is smart enough to store the
          10 as a float on its own, but I'm really not sure. The compiler
          is highly optimized, and generally known to store constants in
          a form best suited for use. But I haven't tested for this
          happening here, so I really don't know.

          However, either way, you will get the same result from the
          division. As pointed out, integer division (\) is not the same
          thing.

          ------------------
          Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

          Comment


          • #6
            Originally posted by Peter Lameijn:
            So:
            Code:
            Vdd  = edtVdd/10.; would become Vdd  = edtVdd/10
                 and
            Vpp  = edtVpp/10;  would become Vpp  = edtVpp\10
            No, it's mean :

            Code:
            Vdd  = edtVdd/10.; would become Vdd  = edtVdd/(float)10
                 and
            Vpp  = edtVpp/10;  would become Vpp  = edtVpp/(long)10
            so decimal point in this case play role of type specifier


            or PB analog:
            Code:
            Vdd  = edtVdd/10.; would become Vdd  = edtVdd/10!
                 and
            Vpp  = edtVpp/10;  would become Vpp  = edtVpp/10&
            Sy,

            ------------------
            -=Alex=-
            -=Alex=-

            Comment


            • #7
              Thanks,

              You are right. Dividing by an integer isn't the same as integer divide...



              ------------------
              Regards,
              Peter
              Regards,
              Peter

              Comment


              • #8
                Still one more question to go...
                I'm puzzled by this line:
                Code:
                public static DeviceData DeviceBuffers;
                The DeviceData is found like this:
                Code:
                {
                    public class DeviceData
                    {
                        public uint[] ProgramMemory;
                        public uint[] EEPromMemory;
                        public uint[] ConfigWords;
                        public uint[] UserIDs;
                        public uint OSCCAL;
                        public uint BandGap;
                        
                        public DeviceData(uint progMemSize, ushort eeMemSize, byte numConfigs, byte numIDs, 
                                            uint memBlankVal, int eeBytes, int idBytes, ushort[] configBlank)
                        {   // Overloaded Constructor
                            ProgramMemory = new uint[progMemSize];
                            EEPromMemory = new uint[eeMemSize];
                            ConfigWords = new uint[numConfigs];
                            UserIDs = new uint[numIDs];
                            
                            //init program memory to blank
                            for (int i = 0; i < progMemSize; i++)
                            {
                                ProgramMemory[i] = memBlankVal;
                            }
                            
                            //init eeprom to blank
                            uint eeBlankVal = 0xFF;
                            if (eeBytes == 2)
                            {
                                eeBlankVal = 0xFFFF;
                            }
                            for (int i = 0; i < eeMemSize; i++)
                            {
                                EEPromMemory[i] = eeBlankVal;                  // 8-bit eeprom will just use 8 LSBs
                            }
                
                            //init configuration to blank
                            for (int i = 0; i < numConfigs; i++)
                            {
                                ConfigWords[i] = configBlank[i];
                            }
                
                            //init user ids to blank
                            uint idBlank = memBlankVal;
                            if (idBytes == 1)
                            {
                                idBlank = 0xFF;
                            }
                            for (int i = 0; i < numIDs; i++)
                            {
                                UserIDs[i] = idBlank;
                            }   
                            
                            //init OSSCAL & BandGap
                            OSCCAL = memBlankVal;
                            BandGap = memBlankVal;
                        
                        }
                    }
                }
                I understand it gives me a Global DeviceBuffers of the type DeviceData, but I'm not sure what to make of it...
                (A pointer to a class or so???)

                ------------------
                Regards,
                Peter
                Regards,
                Peter

                Comment


                • #9
                  DeviceData is a class.
                  Having a function with the same name means the constructor call which is always invoked (if present).
                  A function called on creation.

                  ~DeviceData() is the deconstructor.


                  ------------------
                  http://www.hellobasic.com
                  hellobasic

                  Comment


                  • #10
                    The constructor is forced (since it's present) and you must provide the datasizes:

                    ProgramMemory = new uint[progMemSize]

                    ProgramMemory seems an integer array with size progMemSize (= 0 to progMemSize -1)

                    ------------------
                    http://www.hellobasic.com
                    hellobasic

                    Comment


                    • #11
                      The line:
                      public static DeviceData DeviceBuffers;

                      Is a pre-declaration.
                      Somewhere in your code you should see:

                      DeviceBuffers = new DeviceData (..stuff here...);


                      ------------------
                      http://www.hellobasic.com



                      [This message has been edited by Edwin Knoppert (edited November 27, 2006).]
                      hellobasic

                      Comment


                      • #12
                        Thanks Edwin,

                        Yes, I have a DeviceBuffers = new DeviceData (.....);
                        But it's still not clear what it does. Is it just a simple call to the DeviceData Sub in PB?
                        (Creating a new instance of all data in it?...)

                        ------------------
                        Regards,
                        Peter
                        Regards,
                        Peter

                        Comment


                        • #13
                          A class created is an unique instance.
                          All it's data is unique to this single instance

                          like:
                          public uint[] ProgramMemory;
                          public uint[] EEPromMemory;
                          public uint[] ConfigWords;
                          public uint[] UserIDs;
                          public uint OSCCAL;
                          public uint BandGap;

                          So each instance of the class can hold unique values in the declared variables it contains.

                          You usually would not store a class interface handle in a simple long-int array

                          The constructor is used here is to enforce the filling of the class'es data (the vars and arrays as shown above).

                          The class instance in your c language and can not be shared with other languages (unless it contains activex interfaces)

                          You can expose functions in c to access the class data/methods, or use pointers to parts in the class, which is not really desired.

                          Maybe you need to explain what you want with this.
                          So far it's a simple data container as it seems.


                          ------------------
                          http://www.hellobasic.com



                          [This message has been edited by Edwin Knoppert (edited November 27, 2006).]
                          hellobasic

                          Comment


                          • #14
                            If you are interested, I'm trying to port this C program:
                            http://www.microchip.com/stellent/id...GE&nodeId=1960

                            (Look for PicKit 2 PC Application Source Code V2.01)

                            ------------------
                            Regards,
                            Peter



                            [This message has been edited by Peter Lameijn (edited November 27, 2006).]
                            Regards,
                            Peter

                            Comment


                            • #15
                              Way to much work to investigate.
                              I assume you have nothing working yet?
                              dotnet is so much unicode based.
                              I don't even trust the structures in there, they might have 'gaps' all over..



                              ------------------
                              http://www.hellobasic.com
                              hellobasic

                              Comment


                              • #16
                                Why not stick with this application in dotnet?
                                I re-read the code and it's REALLY a lot of work to rewrite this all to pb.

                                You'll learn dotnet with this


                                ------------------
                                http://www.hellobasic.com
                                hellobasic

                                Comment


                                • #17
                                  A few reasons...

                                  I don't have a compiler for dotNet at the moment, and I hate forcing clients to install dotNet framework on their systems.
                                  (For in the field programming often very old laptops are used...)

                                  I'll rethink it and maybe give it a try later on...



                                  ------------------
                                  Regards,
                                  Peter
                                  Regards,
                                  Peter

                                  Comment

                                  Working...
                                  X