473,499 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array initialization to NULL gives Link error

365 Contributor
Trying to initialize array to NULL, gives Link error (Undefined : "__clear")

Expand|Select|Wrap|Line Numbers
  1. char ip_string[16] = {0};
may be compiler issue?.
anything wrong?. thanks.
Nov 12 '09 #1
5 2674
donbock
2,426 Recognized Expert Top Contributor
Your line of code is not "trying to initialize array to NULL". NULL has a pointer type; you have an array of chars.

The linker error refers to undefined symbol "__clear". Typically, symbols that start with underscore are part of the compiler-provided compile-time or run-time environments.
  • Perhaps your compiler is improperly installed.
  • Perhaps you are missing some environment variable that permits the linker to find the run-time library.
  • Perhaps your PATH is set wrong.
  • Perhaps you need to change some compiler command line argument.
As it happens, you can work around this problem. The default initial value for non-automatic variables that don't have initializers is zero. Your "={0}" initializer is redundant. What happens if you delete it?

By the way, do you intend this to be an array of numbers or an array of text characters? If numbers, then it should be an array of signed char or unsigned char. If text, then your initializer should be a character constant ({'\0'}). This is a pedantic point, it doesn't have anything to do with your linker error.
Nov 12 '09 #2
tvnaidu
365 Contributor
This array to basically I need to copy some text (numbers - like IP address notation) and send the text on serial port to display on LCD, basically I need to initialize the array to NULL, before copy the string, can I do memset to initialize to NULL.

memset(ip_string, 0, sizeof(ip_string);
strcpy(ip_string, "192..........");
Nov 12 '09 #3
donbock
2,426 Recognized Expert Top Contributor
If ip_string is a null-terminated string, then you only need to initialize the first character of the string to null. Nothing is gained by filling the entire array with nulls.
Expand|Select|Wrap|Line Numbers
  1. char ip_string[16] = "";
On the other hand, you might like to do something like this:
Expand|Select|Wrap|Line Numbers
  1. char ip_string[] = "XXX.XXX.XXX.XXX";
  2. ...
  3. ip_string[0] = '\0';        // Set ip_string to "".
Notice that the array size is implied by the length of the initializer string. The advantage here is that it is much easier to see at a glance that the array size is large enough to hold an IP address string.


By the way ... There is no easy way to say this, you are confusing NULL with null. (Sounds like Who's on First.)

NULL [all uppercase] is a macro that is defined by several of the standard header files (stdio.h, stdlib.h, etc). The value of NULL is guaranteed to be 0. This macro is used wherever you want to indicate a pointer that doesn't point to anything (a NULL pointer).

Null [mixed-case or all lowercase] is the name of the character used to terminate strings. The value of null is guaranteed to be '\0'. The compiler does not predefine a macro or symbol named "null". The term 'null' is similar to terms like 'function' or 'operand' in that none of these terms have any special meaning to the compiler, but programmers use them to describe what they are doing.
Nov 13 '09 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
char ip_string[16] = {0};
Your initialization code works just fine.

There must be a problem with your compiler.

The 0 is an int which converts to a char with no problem.
Nov 13 '09 #5
tvnaidu
365 Contributor
Thanks. It is compiler issue. I just declared and inside I am doing memset that array to zero.
Nov 15 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
8451
by: dam_fool_2003 | last post by:
Friends, cannot we malloc a array? So, I tried the following code: int main(void) { unsigned int y={1,3,6},i,j; for(i=0;i<3;i++) printf("before =%d\n",y); *y = 7; /* 1*/
8
3662
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
12
2724
by: flipflop | last post by:
I need to create a global array whose dimensions depend on the contents of another global array populated at its initialisation. For example: int array1={3,2,1}; int array2]; //should be...
11
3754
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
6
34756
by: Kannan | last post by:
Hi, I have question about character array initialization. In section 6.7.8 paragraph number 21, it's given that "If there are fewer initializers in a brace-enclosed list than there are...
2
4439
by: JennyWren | last post by:
I have an array of structs which I will be going through one-by-one to search for a matching value. This array might have elements added and removed later, so I don't want to have to update a...
152
9721
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 = { {...
3
4828
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
2
3472
by: aaragon | last post by:
Hello everyone, Is this valid? template <class A> struct ClassA { typedef A value_type; value_type* data_;
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4917
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
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
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
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
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 ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.