Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #define and data types

#define and data types

Scheduled Pinned Locked Moved C / C++ / MFC
questioncollaboration
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James A Beggs
    wrote on last edited by
    #1

    Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

    P R 2 Replies Last reply
    0
    • J James A Beggs

      Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

      P Offline
      P Offline
      Pavel Klocek
      wrote on last edited by
      #2

      #define is a preprocessor job, it simply defines text to replace in source code before it's passed to compiler. It does know nothing about types. Pavel Sonork 100.15206

      M 1 Reply Last reply
      0
      • P Pavel Klocek

        #define is a preprocessor job, it simply defines text to replace in source code before it's passed to compiler. It does know nothing about types. Pavel Sonork 100.15206

        M Offline
        M Offline
        Maciej Pirog
        wrote on last edited by
        #3

        Yeah! He's right. This code:

        #define XXX void function(int r)
        static XXX
        {

        }

        will be seen by the comiler as:

        static void function(int r)
        {

        }

        You can write anything after #define

        Ñ There is only one MP Ð

        1 Reply Last reply
        0
        • J James A Beggs

          Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

          R Offline
          R Offline
          RedZenBird
          wrote on last edited by
          #4

          why not consider: const char xmlBeginStatement[] = "<"; some would consider it be be 'better form'....... Just trying to keep the forces of entropy at bay

          J 1 Reply Last reply
          0
          • R RedZenBird

            why not consider: const char xmlBeginStatement[] = "<"; some would consider it be be 'better form'....... Just trying to keep the forces of entropy at bay

            J Offline
            J Offline
            James A Beggs
            wrote on last edited by
            #5

            I did. I had decided on using defines at the time. I'm certainly not married to it, however.

            R 1 Reply Last reply
            0
            • J James A Beggs

              I did. I had decided on using defines at the time. I'm certainly not married to it, however.

              R Offline
              R Offline
              RedZenBird
              wrote on last edited by
              #6

              Meyer's will argue that using const definitions over #define is the way to go...I agree with him.... Just trying to keep the forces of entropy at bay

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups