473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Arrays as macro

Hello,

Lets say one wants to create an array of unsigned chars which would be
stored and used as a macro.
What syntax options do I have to do this?

E.g. if I have a string I would do:

#define MY_STRING "test"

However I cannot declare {1, 2, 3, 4} without variable names.
If I do

#define MY_ARRAY "\x01\x02\x03\x04"
then sizeof won't report 4 but 5.

Is there anything I'm missing or is it not possible?

Thanks.

-- Henrik
May 22 '07 #1
1 6113
Henrik Goldman wrote:
Lets say one wants to create an array of unsigned chars which would be
stored and used as a macro.
What syntax options do I have to do this?

E.g. if I have a string I would do:

#define MY_STRING "test"

However I cannot declare {1, 2, 3, 4} without variable names.
No, you cannot. It's called a compound initialiser and it is only
allowed in a declaration statements, to initialise an array or
an object of POD type.
If I do

#define MY_ARRAY "\x01\x02\x03\x04"
then sizeof won't report 4 but 5.
Correct. String literals have an extra element - the terminating
null character.
Is there anything I'm missing or is it not possible?
There are no "array literals" in C++ yet. What exactly are you trying
to accomplish?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Scott McPhillips [MVP] | last post by:
I have a fixed-size string array like this char m_titles; and can't figure out how to change it to a dynamically-sized vector like this: std::vector<char> m_titles; The declaration...
50
by: jacob navia | last post by:
As everybody knows, the C language lacks a way of specifying bounds checked arrays. This situation is intolerable for people that know that errors are easy to do, and putting today's powerful...
5
by: chella mani | last post by:
hi all, I am developing a tool for scientific application which must be time and memory efficient,my tool uses 1D,2D and 3D arrays. Is it a good practice to use 3D arrays in applications or I...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
5
by: al3x4nder | last post by:
look this code: #include <stdio.h> #define length(arr) sizeof(arr)/sizeof(arr) void func(int arr){ printf("func(): length(arr) = %d\n", length(arr)); } void main(void){
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
3
by: Mike Cain | last post by:
I have an odd situation I'm trying to understand..... I'm using MS VS 7.0 C++ with the MFC CBuffer class. If I do this: #define NUM_ELEMENTS 2 CBuffer<char, 512 x; CBuffer<char, 512 ...
11
by: Sunny | last post by:
#include <iostream> int main() { int len; std::cin >len; int Arr; int *p = new int; Arr=5; std::cout << &len << " " << &Arr << " " << p << std::endl;
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.