-2

I write a code:

int main()
{
    long long a = 1a1b2a2b3a3b4a4b;
    long *p1;
    long *p2;
    long *p3;
    long *p4;
    *p1 = 1a1b;
    *p2 = 2a2b;
    *p3 = 3a3b;
    *p4 = 4a4b;

    *p1 = &p2;
    *p2 = &p3;
    *p3 = &p4;

    printf("Die folgende Zahl : %11x", &p1, &p2, &p3, &p4);
}

and get this error:

invalid suffix "1a1b2a2b3a3b4a4b" on integer constant

Could any one help whats my mistake?

Stargateur
  • 24,473
  • 8
  • 65
  • 91
Roman
  • 113
  • 1
  • 1
  • 6
  • You should add the hex prefix to tell the compiler that the number is in hex format and not decimal. – lpares12 Jun 03 '17 at 07:54
  • 3
    Try a `0x1a1b2a2b3a3b4a4b`. – Yunnosch Jun 03 '17 at 07:55
  • 1
    Welcome to StackOverflow. Please take the [tour]. Formatting would be helpful. – Yunnosch Jun 03 '17 at 07:55
  • 1
    There are two questions here, "What is the reason for the quoted error?" and "What other things should be fixed in this code?" Answers should definitly answer the first question and should be careful not to be caught by the second. – Yunnosch Jun 03 '17 at 08:04
  • Reason is, not having understanding yet, what that is and how it is supposed to be fixed. – Roman Jun 03 '17 at 08:07
  • @Yunnosch no, to the value of the pointer (note the `*`). Anyways, the pointers are not pointing to any location, and that's a ticket to undefined behaviour. – lpares12 Jun 03 '17 at 08:08
  • The number looks like a "1" with a long, unknown suffix. A correct suffix would be e.g. "LL", making the literal a long long literal. With the **pre**fix "0x", it becomes a hexadecimal literal. – Yunnosch Jun 03 '17 at 08:09
  • @Yunnosch yeah I see what you mean, I wanted to say `*p1=0x1a1b`, a shame that I can't edit the comment now. – lpares12 Jun 03 '17 at 08:14
  • @lpares12 You can delete it and write the one you meant. That will give it a "later" place in the comment thread, but look better in total. – Yunnosch Jun 03 '17 at 08:15
  • You will have the same problem for the `*p1=1a1b` statements, where you should do `*p1=0x1a1b`, remember to add the hex prefix. Although the pointers and not pointing to anything, and I don't really know which behavior to expect in that scenario. – lpares12 Jun 03 '17 at 08:16
  • In case you wonder about the downvote (which is not by me), it might be because an internet search for "C suffix" gives you helpful explanations (though on C++) in what is the very first hit (in my preferred search engine): http://en.cppreference.com/w/cpp/language/integer_literal Explanations strictly for C are harder to find, that is why I did not downvote. – Yunnosch Jun 03 '17 at 08:47
  • i don't care about ratings, i want answers. – Roman Jun 03 '17 at 08:48
  • I admire not caring for the ratings. But you have better hope for good, fast answers with good questions. Even if I often disagree with our beloved mystery-downvoters, it sadly is necessary to avoid them. Many potentially helpful users ignore sub-zero-questions, not without reason. – Yunnosch Jun 03 '17 at 08:51
  • About what should the program do. Should be writen a program that does have in the main part, a variable of type long long initialised with hexa 1a1b2a2b3a3b4a4b. The double Bytes should be possibly interpreted as Unicode-Symbols. Define 4 Pointers that point at next Double Byte (1a1b, 2a2b, 3a3b, 4a4b). The Adresses and the Value of Double Bytes should be given out in stdout. Also it have something to do with ULL Suffix and Format %11x. – Roman Jun 03 '17 at 09:02

2 Answers2

1

Although you haven't explained what you are trying to do in that code, I'll try to give you a brief explanation on why you are getting that error.

You are declaring a variable of type long long and assigning it a value of 1a1b2a2b3a3b4a4b. Usually, when you assign a value to a variable, you should enter the value in decimal, and as you can see 1a1b2a2b3a3b4a4b is not decimal.

First of all, compiling with cc in ubuntu, returns the error:

invalid suffix "a1b2a2b3a3b4a4b" on integer constant

Note that the first 1 is not shown.

The compiler expects an integer literal (or integer literal + suffix L for long) when assigning a value to a variable of type long. Your problem is that the compiler is understanding the first 1 as an integer literal and a1b2a2b3a3b4a4b as a suffix. Since this suffix doesn't exist, you get the error.

I assume what you are trying to do is assigning the hexadecimal value 1a1b2a2b3a3b4a4b to the variable a. If that's what you are trying to do, you should specify that the value you are entering is in hexadecimal. The way to do that, is to add the 0x prefix before the value, so it would look like this:

long long a = 0x1a1b2a2b3a3b4a4b;

There's more information on valid integer literals here.

Anyways, there are lots of other mistakes in your code, like assigning a value to what the pointers point to before specifying what the pointers point to.

lpares12
  • 3,504
  • 4
  • 24
  • 45
  • `0x` is a prefix. Suffixes are at the end. – Yunnosch Jun 03 '17 at 08:16
  • Would you like to remove the non-C-syntax backtick? And add a `;` for a complete statement/initialisation and remove the `"`. – Yunnosch Jun 03 '17 at 08:20
  • Breathe slowly. Read, think, edit, read again, fix, post. ;-) – Yunnosch Jun 03 '17 at 08:22
  • Maybe improve by explaining why the error talks about wrong **suf**fix, while the solution (which I agree with) is to add a **pre**fix. I think OP has indicated in a comment being interested in this detail. – Yunnosch Jun 03 '17 at 08:32
0

When assigning a hexadecimal value to a variable, you need to prefix it with 0x - like:

long long a = 0x1a1b2a2b3a3b4a4b;

However, the worst part is this:

long *p1;
.....
*p1 = 1a1b;  // note: should be 0x1a1b

Here you define a pointer p1 and then assigns a value to the memory that the pointer points to. That is a huge mistake because the pointer is uninitialized, i.e. is does not point to any legal memory.

You need to allocate memory first, e.g.:

long *p1 = malloc(sizeof(*p1));
*p1 = 0x1a1b;
....
free(p1);
Support Ukraine
  • 42,271
  • 4
  • 38
  • 63
  • Greatful for your feedback, i just started learning about C. Would you care to explain how does ULL work, how it should be implimented in the code ? – Roman Jun 03 '17 at 08:45
  • If you start talking about shortcomings the question is not explicitly asking about go all the way and get it warning-free compilable. – Yunnosch Jun 03 '17 at 08:56