Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for norminette #3910

@cassepipe

cassepipe commented Sep 18, 2021 • edited Loading

norminette

The tuition-free is using a program to check whether the C code written for the school projects and submitted to peer-review follows a certain style. Its purpose is to enforce a common style that is easily readable by others.

It is easily installed with :

Here is an example of what the outputs in the terminal:

Writing a linter for it should be trivial for someone well versed in Vimscript but alas this not my case.

I have not been able to find help to make it work so far so I am asking here in the hope
that someone can show me the way forward. Here is my (non-functional) attempt at it :

ale#Set('c_norminette_executable', 'norminette') call ale#Set('c_norminette_options', '') function! ale_linters#c#norminette#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_norminette_executable') endfunction function! ale_linters#c#norminette#GetCommand(buffer) abort return ale#Escape(ale_linters#c#norminette#GetExecutable(a:buffer)) \ . ale#Var(a:buffer, 'c_norminette_options') \ . ' %t' endfunction function! ale_linters#c#norminette#Opscript(buffer, lines) abort " Look for lines like the following. " "ft_lstsize.c: Error! "Error: SPACE_REPLACE_TAB (line: 17, col: 11): Found space when expecting tab "ft_calloc.c: OK! "ft_memcpy.c: Error! "Error: SPACE_AFTER_KW (line: 22, col: 19): Missing space after keyword "test.c: Error! "Error: SPACE_BEFORE_FUNC (line: 6, col: 4): space before function name "Error: WRONG_SCOPE_COMMENT (line: 12, col: 9): Comment is invalid in this scope "ft_isalnum.c: OK! let l:pattern = '\(^\(\h\+\.[ch]\): \(\w\+\)!$\|^Error: \h\+\s\+(line:\s\+\(\d\+\),\s\+col:\s\+\(\d\+\)):\s\+\(.*\)\)' let l:output = [] let l:curr_file = '' for l:match in ale#util#GetMatches(a:lines, l:pattern) if l:match[2] == 'OK' continue elseif l:match[2] == "Error" let l:curr_file = l:match[1] " if ale#path#IsBufferPath(a:buffer, l:curr_file) && l:match[1] == "Error" else call add(l:output, { \ 'lnum': str2nr(l:match[1]), \ 'col': str2nr(l:match[2]), \ 'type': 'E', \ 'text': l:match[3], \}) endif endfor return l:output endfunction call ale#linter#Define('c', { \ 'name': 'norminette', \ 'output_stream': 'both', \ 'executable': function('ale_linters#c#norminette#GetExecutable'), \ 'command': function('ale_linters#c#norminette#GetCommand'), \ 'callback': 'ale_linters#c#norminette#Opscript', \})

Any help or hint would be much appreciated. Thanks for making ALE, I could write code that fast without it.

@cassepipe

hsanson commented Sep 19, 2021

On simple inspection this looks like should work. What problem do you see or what is not working?

Sorry, something went wrong.

cassepipe commented Sep 19, 2021 • edited Loading

Well, it does work, I get a at the top of the file and I see no error message.
I suspect I don't understand very well how the matching function work and/or I get my indexing wrong.
I am pretty sure about my pattern though as I tested it on the output thanks to the option in Vim.
I just don't know how to debug it

hsanson commented Sep 19, 2021 • edited Loading

You can run the same commands used in the script inside vim to test the regexp. For example I ran these commands:

And this was the output:

The regexp works but you are checking or when that value is in . The filename would be in instead of . You can test the other error messages to figure out the correct match index.

Also since we get errors for different files is better to add the to the list of errors:

Hope this helps you implement the linter. I recommend you submit a PR to make the discussion easier. Do not forget to add documentation, tests, and update the list of supported tools. See for details.

cassepipe commented Sep 19, 2021

Thanks for the debugging tip !
And thanks for pointing out to where the error is and giving advice for betterment.
I will try that out ASAP.
If I mange to make it work, I'll do the work of documenting it and submit a PR.
I don't think I have the level needed to write tests but I will look into that too.

No branches or pull requests

@hsanson

  • Trending Now
  • Foundational Courses
  • Data Science
  • Practice Problem
  • Machine Learning
  • System Design
  • DevOps Tutorial

Control Structures in Programming Languages

Control Structures are just a way to specify flow of control in programs. Any algorithm or program can be more clear and understood if they use self-contained modules called as logic or control structures. It basically analyzes and chooses in which direction a program flows based on certain parameters or conditions. There are three basic types of logic, or flow of control, known as:

  • Sequence logic, or sequential flow
  • Selection logic, or conditional flow
  • Iteration logic, or repetitive flow

Let us see them in detail:

Sequential logic as the name suggests follows a serial or sequential flow in which the flow depends on the series of instructions given to the computer. Unless new instructions are given, the modules are executed in the obvious sequence. The sequences may be given, by means of numbered steps explicitly. Also, implicitly follows the order in which modules are written. Most of the processing, even some complex problems, will generally follow this elementary flow pattern.

error assign_in_control assignment in control structure

Sequential Control flow

Selection Logic simply involves a number of conditions or parameters which decides one out of several written modules. The structures which use these type of logic are known as Conditional Structures . These structures can be of three types:

Implementation:

  • C/C++ if statement with Examples
  • Java if statement with Examples
  • C/C++ if-else statement with Examples
  • Java if-else statement with Examples
  • C/C++ if-else if statement with Examples
  • Java if-else if statement with Examples

In this way, the flow of the program depends on the set of conditions that are written. This can be more understood by the following flow charts:

error assign_in_control assignment in control structure

Double Alternative Control Flow

Here, A is the initial value, N is the end value and I is the increment. The loop ends when A>B. K increases or decreases according to the positive and negative value of I respectively.

error assign_in_control assignment in control structure

Repeat-For Flow

  • C/C++ for loop with Examples
  • Java for loop with Examples

error assign_in_control assignment in control structure

Repeat While Flow

  • C/C++ while loop with Examples
  • Java while loop with Examples

author

Please Login to comment...

Similar reads.

  • Programming Language
  • How to Get a Free SSL Certificate
  • Best SSL Certificates Provider in India
  • Elon Musk's xAI releases Grok-2 AI assistant
  • What is OpenAI SearchGPT? How it works and How to Get it?
  • Content Improvement League 2024: From Good To A Great Article

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

  • The Book of C (version 2022.08) »
  • 4. Control Structures

4. Control Structures ¶

In this chapter, we encounter the set of "control" structures in C, such as conditional statements and looping constructs. As a preview, the control structures in C are nearly identical to those found in Java (since Java syntax is heavily based on C), and bear strong resemblance to control structures found in other programming languages.

4.1. if Statement ¶

Both an if and an if-else are available in C. The <expression> can be any valid C expression. The parentheses around the expression are required, even if it is just a single variable:

You should always use curly braces around the statement block associated with an if statement. Although C allows a programmer not to include the curly braces in the case of if statements and other control structures when there is only a single statement in the statement block, you should always use the curly braces . Why, you ask, should I type those additional characters? Just ask the unfortunate engineering group at Apple that introduced the "goto fail" bug into their SSL (secure sockets layer) library: a bug that affected the macOS and iOS operating systems quite severely [ 1 ] . The upshot of this security failure is that it could have been prevented with the rigorous use of curly braces for all statement blocks.

So, for the simple form of the if statement shown above, you should really write:

As in Java, the else keyword can be used to provide alternative execution for a conditional expression. Also similar to Java, multiple if ... else if statements can be chained together. There is no elif as in Python (or elsif as in Ruby).

4.2. The conditional expression (ternary operator) ¶

The conditional expression can be used as a shorthand for some if-else statements. The general syntax of the conditional operator is:

This is an expression , not a statement , so it represents a value. The operator works by evaluating expression1 . If it is true (non-zero), it evaluates and returns expression2 . Otherwise, it evaluates and returns expression3 .

The classic example of the ternary operator is to return the smaller of two variables. Instead of writing:

you can write:

The ternary operator is viewed by some programmers as "excessively tricky" since expressions with such operators can be hard to read. Use your best judgment, and don't do something this [Horrific] example.

4.3. switch statement ¶

The switch statement is a sort of specialized form of if with the goal of efficiently separating different blocks of code based on the value of an integer. The switch expression is evaluated, and then the flow of control jumps to the matching const-expression case . The case expressions are typically int or char constants (unfortunately, you cannot use strings as case expressions). The switch statement is probably the single most syntactically awkward and error-prone feature of the C language:

Each constant needs its own case keyword and a trailing colon (:). Once execution has jumped to a particular case, the program will keep running through all the cases from that point down --- this so called fall through operation is used in the above example so that expression-3 and expression-4 run the same statements. The explicit break statements are necessary to exit the switch . Omitting the break statements is a common error --- it compiles, but leads to inadvertent, unexpected, and likely erroneous fall-through behavior.

Why does the switch statement fall-through behavior work the way it does? The best explanation might be that C was originally developed for an audience of assembly language programmers. The assembly language programmers were used to the idea of a "jump table" with fall-through behavior, so that's the way C does it (it's also relatively easy to implement it this way). Unfortunately, the audience for C is now quite different, and the fall-through behavior is widely regarded as an unfortunate part of the language.

4.4. while loop ¶

The while loop evaluates the test expression before every loop, so it can execute zero times if the condition is initially false. The conditional expression requires parentheses like the if:

Although the curly braces are not technically required if there is only one statement in the body of the while loop, you should always use the curly braces. Again, see [ 1 ] for why.

4.5. do-while loop ¶

Like a while loop, but with the test condition at the bottom of the loop. The loop body will always execute at least once. The do-while tends to be an unpopular area of the language. Although many users of C use the straight while if possible, a do-while loop can be very useful in some situations:

4.6. for loop ¶

The for loop in C contains three components that are often used in looping constructs, making it a fairly convenient statement to use. The three parts are an initializer, a continuation condition, and an action, as in:

The initializer is executed once before the body of the loop is entered. The loop continues to run as long as the continuation condition remains true. After every execution of the loop, the action is executed. The following example executes 10 times by counting 0..9. Many loops look very much like the following:

C programs often have series of the form 0..(some_number-1). It's idiomatic in C for loops like the example above to start at 0 and use < in the test so the series runs up to but not equal to the upper bound. In other languages you might start at 1 and use <= in the test.

Each of the three parts of the for loop can be made up of multiple expressions separated by commas. Expressions separated by commas are executed in order, left to right, and represent the value of the last expression.

Note that in the C standard prior to C99, it was illegal to declare a variable in the initializer part of a for loop. In C99, however, it is perfectly legal. If you compile the above code using gcc without the -std=c99 flag, you will get the following error:

Once the -std=c99 flag is added, the code compiles correctly, as expected.

4.6.1. break ¶

The break statement causes execution to exit the current loop or switch statement. Stylistically speaking, break has the potential to be a bit vulgar. It is preferable to use a straight while with a single conditional expression at the top if possible, but sometimes you are forced to use a break because the test can occur only somewhere in the midst of the statements in the loop body. To keep the code readable, be sure to make the break obvious --- forgetting to account for the action of a break is a traditional source of bugs in loop behavior:

The break does not work with if ; it only works in loops and switches. Thinking that a break refers to an if when it really refers to the enclosing while has created some high-quality bugs. When using a break , it is nice to write the enclosing loop to iterate in the most straightforward, obvious, normal way, and then use the break to explicitly catch the exceptional, weird cases.

4.6.2. continue ¶

The continue statement causes control to jump to the bottom of the loop, effectively skipping over any code below the continue . As with break , this has a reputation as being vulgar, so use it sparingly. You can almost always get the effect more clearly using an if inside your loop:

4.6.3. Statement labels and goto ¶

Continuing the theme of statements that have a tendency of being a bit vulgar, we come to the king of vulgarity, the infamous goto statement [Goto] . The structure of a goto statement in C is to unconditionally jump to a statement label, and continue execution from there. The basic structure is:

The goto statement is not uncommon to encounter in operating systems code when there is a legitimate need to handle complex errors that can happen. A pattern that you might see is something like:

Notice the structure above: there are multiple steps being performed to carry out some initialization for an operation [ 2 ] . If one of those initialization operations fails, code execution transfers to a statement to handle deinitialization , and those de-init operations happen in reverse order of initialization . It is possible to rewrite the above code to use if / else structures, but the structure becomes much more complex (see an exercise below). Although goto has the reputation of leading to "spaghetti code", judicious use of this statement in situations like the above makes for cleaner and clearer code.

Rewrite the goto example code above (the last code example, above) to use if / else instead. Which code do you think exhibits a more clear structure?

Consider the following program snippet:

What is printed if the number 3 is entered?

Say that you want to write a program that repeatedly asks for a snowfall amount, and that you want to keep asking for another value until the sum of all values exceeds a certain value. What control structure would work best to facilitate entry of the snowfall values, and why?

Say you want to write a program that computes the average of quiz scores. You have a big stack of quizzes, so you do not know the number of quizzes up front. What control structure would work best to facilitate entry of the scores, and why?

Say that you want to simulate rolling a die (singular of dice) a fixed number of times and to compute and print the average value for the die rolls. What control structure would work best for this problem, and why?

http://thedailywtf.com/articles/One-Bad-Ternary-Operator-Deserves-Another

Dijkstra. Letters to the editor: go to statement considered harmful. Communications of the ACM, Volume 11, Issue 3, March 1968. https://dl.acm.org/citation.cfm?id=362947

Table of Contents

  • 4.1. if Statement
  • 4.2. The conditional expression (ternary operator)
  • 4.3. switch statement
  • 4.4. while loop
  • 4.5. do-while loop
  • 4.6.1. break
  • 4.6.2. continue
  • 4.6.3. Statement labels and goto

Previous topic

3. Basic Types and Operators

5. Arrays and Strings

Quick search

Got issues.

If you find a bug or have a suggestion for improvement, please report it .

Assignment and Control

Cite this chapter.

error assign_in_control assignment in control structure

  • Peter Grogono 2  

49 Accesses

Programs may exhibit complex behavior even though they are built from simple components. The complexity arises from the interdependence of computations and data in the program. Obviously, the computations determine the results produced. Less obviously, but equally important, the result produced by each computation may affect a future computation. Managing the interdependence of computations and data is one of the major tasks of programming. Assignments and control structures are essential tools that help us to perform this task. Assignments give new values to variables. Control structures use results to control the order in which computations are performed.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save.

  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Unable to display preview.  Download preview PDF.

Author information

Authors and affiliations.

Department of Computer Science, Concordia University, H3G 1M8, Montreal, Quebec, Canada

Peter Grogono

You can also search for this author in PubMed   Google Scholar

Rights and permissions

Reprints and permissions

Copyright information

© 1995 Springer-Verlag New York, Inc.

About this chapter

Grogono, P. (1995). Assignment and Control. In: Programming with Turing and Object Oriented Turing. Springer, New York, NY. https://doi.org/10.1007/978-1-4612-4238-3_2

Download citation

DOI : https://doi.org/10.1007/978-1-4612-4238-3_2

Publisher Name : Springer, New York, NY

Print ISBN : 978-0-387-94517-0

Online ISBN : 978-1-4612-4238-3

eBook Packages : Springer Book Archive

Share this chapter

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Publish with us

Policies and ethics

  • Find a journal
  • Track your research
  • Control Structures
Info: JavaScript is currently disabled, code tabs will still work, but preferences will not be remembered.

Scala has the control structures you find in other programming languages, and also has powerful for expressions and match expressions:

for loops and expressions

Match expressions, while loops.

  • try / catch

These structures are demonstrated in the following examples.

Scala’s if / else control structure looks similar to other languages.

Note that this really is an expression —not a statement . This means that it returns a value, so you can assign the result to a variable:

As you’ll see throughout this book, all Scala control structures can be used as expressions.

An expression returns a result, while a statement does not. Statements are typically used for their side-effects, such as using println to print to the console.

The for keyword is used to create a for loop. This example shows how to print every element in a List :

The code i <- ints is referred to as a generator . In any generator p <- e , the expression e can generate zero or many bindings to the pattern p . The code that follows the closing parentheses of the generator is the body of the loop.
The code i <- ints is referred to as a generator , and the code that follows the do keyword is the body of the loop.

You can also use one or more if expressions inside a for loop. These are referred to as guards . This example prints all of the numbers in ints that are greater than 2 :

You can use multiple generators and guards. This loop iterates over the numbers 1 to 3 , and for each number it also iterates over the characters a to c . However, it also has two guards, so the only time the print statement is called is when i has the value 2 and j is the character b :

for expressions

The for keyword has even more power: When you use the yield keyword instead of do , you create for expressions which are used to calculate and yield results.

A few examples demonstrate this. Using the same ints list as the previous example, this code creates a new list, where the value of each element in the new list is twice the value of the elements in the original list:

Scala’s control structure syntax is flexible, and that for expression can be written in several other ways, depending on your preference:

This example shows how to capitalize the first character in each string in the list:

Finally, this for expression iterates over a list of strings, and returns the length of each string, but only if that length is greater than 4 :

for loops and expressions are covered in more detail in the Control Structures sections of this book, and in the Reference documentation .

Scala has a match expression, which in its most basic use is like a Java switch statement:

However, match really is an expression, meaning that it returns a result based on the pattern match, which you can bind to a variable:

match isn’t limited to working with just integer values, it can be used with any data type:

In fact, a match expression can be used to test a variable against many different types of patterns. This example shows (a) how to use a match expression as the body of a method, and (b) how to match all the different types shown:

Because the method getClassAsString takes a parameter value of type Any , it can be decomposed by any kind of pattern.

The method getClassAsString takes as a parameter a value of type Matchable , which can be any type supporting pattern matching (some types don’t support pattern matching because this could break encapsulation).

There’s much more to pattern matching in Scala. Patterns can be nested, results of patterns can be bound, and pattern matching can even be user-defined. See the pattern matching examples in the Control Structures chapter for more details.

try / catch / finally

Scala’s try / catch / finally control structure lets you catch exceptions. It’s similar to Java, but its syntax is consistent with match expressions:

Scala also has a while loop construct. Its one-line syntax looks like this:

Scala 3 still supports the Scala 2 syntax for the sake of compatibility.

The while loop multiline syntax looks like this:

Custom control structures

Thanks to features like by-name parameters, infix notation, fluent interfaces, optional parentheses, extension methods, and higher-order functions, you can also create your own code that works just like a control structure. You’ll learn more about this in the Control Structures section.

Contributors to this page:

  • Introduction
  • Scala Features
  • Why Scala 3?
  • A Taste of Scala
  • Hello, World!
  • Variables and Data Types
  • Domain Modeling
  • First-Class Functions
  • Singleton Objects
  • Collections
  • Contextual Abstractions
  • Toplevel Definitions
  • A First Look at Types
  • String Interpolation
  • OOP Modeling
  • FP Modeling
  • Method Features
  • Main Methods in Scala 3
  • Anonymous Functions
  • Function Variables
  • Eta-Expansion
  • Higher-Order Functions
  • Write Your Own map Method
  • Creating a Method That Returns a Function
  • Packaging and Imports
  • Scala Collections
  • Collections Types
  • Collections Methods
  • Functional Programming
  • What is Functional Programming?
  • Immutable Values
  • Pure Functions
  • Functions Are Values
  • Functional Error Handling
  • Types and the Type System
  • Inferred Types
  • Intersection Types
  • Union Types
  • Algebraic Data Types
  • Opaque Types
  • Structural Types
  • Dependent Function Types
  • Other Types
  • Extension Methods
  • Context Parameters
  • Context Bounds
  • Given Imports
  • Type Classes
  • Multiversal Equality
  • Implicit Conversions
  • Concurrency
  • Scala Tools
  • Building and Testing Scala Projects with sbt
  • Interacting with Java
  • Scala for Java Developers
  • Scala for JavaScript Developers
  • Scala for Python Developers
  • Where To Go Next

Next: Unions , Previous: Overlaying Structures , Up: Structures   [ Contents ][ Index ]

15.13 Structure Assignment

Assignment operating on a structure type copies the structure. The left and right operands must have the same type. Here is an example:

Notionally, assignment on a structure type works by copying each of the fields. Thus, if any of the fields has the const qualifier, that structure type does not allow assignment:

See Assignment Expressions .

When a structure type has a field which is an array, as here,

structure assigment such as r1 = r2 copies array fields’ contents just as it copies all the other fields.

This is the only way in C that you can operate on the whole contents of a array with one operation: when the array is contained in a struct . You can’t copy the contents of the data field as an array, because

would convert the array objects (as always) to pointers to the zeroth elements of the arrays (of type struct record * ), and the assignment would be invalid because the left operand is not an lvalue.

  • MATLAB Answers
  • File Exchange
  • AI Chat Playground
  • Discussions
  • Communities
  • Treasure Hunt
  • Community Advisors
  • Virtual Badges
  • Trial software

You are now following this question

  • You will see updates in your followed content feed .
  • You may receive emails, depending on your communication preferences .

error Structure assignment to non-structure object

Marwen Tarhouni

Direct link to this question

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object

   2 Comments Show None Hide None

Geoff Hayes

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_399718

Marwen Tarhouni

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_399762

Sign in to comment.

Sign in to answer this question.

Answers (1)

KSSV

Direct link to this answer

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#answer_239654

   4 Comments Show 2 older comments Hide 2 older comments

KSSV

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_399792

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_399887

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_400084

https://www.mathworks.com/matlabcentral/answers/307922-error-structure-assignment-to-non-structure-object#comment_400120

  • femtocell.m
  • matlab function
  • cell arrays

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

  • América Latina (Español)
  • Canada (English)
  • United States (English)
  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 简体中文 Chinese
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Contact your local office

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

incompatible types when assigning to type struct * from struct

I can't understand why i get this error : The error is : "incompatible types when assigning to type 'PERSOANA * {aka struct *}' from type 'PERSOANA {aka struct }' " Can you please explain me where is the mistake ?

  • dynamic-memory-allocation

ballow's user avatar

  • 1 You try to return a pointer to a struct when you declared to return a struct. –  Osiris Commented Jan 8, 2019 at 19:52
  • 3 PERSON *read_array(int n) should be the correct syntax. –  Osiris Commented Jan 8, 2019 at 19:53
  • 2 Please quote the error message in full and verbatim. It is unlikely that what you quoted is actually the exact and full message. –  Yunnosch Commented Jan 8, 2019 at 19:57
  • Now it works, thx a lot mate !:) –  ballow Commented Jan 8, 2019 at 20:01
  • type of v is PERSON* and return type of the function prototype is PERSON. –  Stef1611 Commented Jan 8, 2019 at 20:01

2 Answers 2

Return a pointer to PERSON , not the object PERSON .

I can't understand why i get this error : Incompatible types when assigning to type PERSON from type PERSON.

I am reasonably confident that you do not get that error, but if you actually do then you should switch to a better compiler. I speculate that the error you get is instead

, because that's in fact what you are trying to do, given your declaration of function read_array() .

From implementation and use, it appears that you want that function to return a pointer to a structure rather than a copy of the structure. That would be

... and the same in the function definition.

John Bollinger's user avatar

  • Sorry for the misunderstanding, i redited my question, that's the error i've got :) Thanks a lot –  ballow Commented Jan 8, 2019 at 20:08

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged c pointers struct dynamic-memory-allocation or ask your own question .

  • The Overflow Blog
  • From PHP to JavaScript to Kubernetes: how one backend engineer evolved over time
  • Where does Postgres fit in a world of GenAI and vector databases?
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Bringing clarity to status tag usage on meta sites
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • What does a new user need in a homepage experience on Stack Overflow?
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Stealth Mosquitoes?
  • What is the spiritual difference between hungering and thirsting? (Matthew 5:6)
  • How can these humans cross the ocean(s) at the first possible chance?
  • Sci-fi short story about a dystopian future where all natural resources had been used up and people were struggling to survive
  • Replacing a multi character pattern that includes a newline with some characters
  • I'm trying to remember a novel about an asteroid threatening to destroy the earth. I remember seeing the phrase "SHIVA IS COMING" on the cover
  • Why does Russia strike electric power in Ukraine?
  • My collegeagues and I are travelling to UK as delegates in an event and the company is paying for all our travel expenses. what documents are required
  • Is 2'6" within the size constraints of small, and what would the weight of a fairy that size be?
  • Where did Geordi's eyes go?
  • How would increasing atomic bond strength affect nuclear physics?
  • Can I use "historically" to mean "for a long time" in "Historically, the Japanese were almost vegetarian"?
  • Can a 2-sphere be squashed flat?
  • Submitting a paper as a nonacademic practitioner in a field
  • What was I thinking when I made this grid?
  • Why is Emacs recompiling some packages on every startup?
  • How do you hide an investigation of alien ruins on the moon during Apollo 11?
  • Completely introduce your friends
  • Amount Transfer Between Different Accounts
  • How do I safely remove a mystery cast iron pipe in my basement?
  • How can suzanne be scaled relative to the box in geometry nodes?
  • Simple casino game
  • Why do National Geographic and Discovery Channel broadcast fake or pseudoscientific programs?
  • What issues are there with my perspective on truth?

error assign_in_control assignment in control structure

IMAGES

  1. Chapter 5 Control Structures

    error assign_in_control assignment in control structure

  2. A general control structure for error correction with indication of

    error assign_in_control assignment in control structure

  3. An example of control structure modeling.

    error assign_in_control assignment in control structure

  4. How to Use Error Handling Options and Techniques in Informatica

    error assign_in_control assignment in control structure

  5. Decision Control Structure

    error assign_in_control assignment in control structure

  6. Guide: Error Handling Integration Patterns

    error assign_in_control assignment in control structure

COMMENTS

  1. In C++ what causes an assignment to evaluate as true or false when used

    An assignment statement evaluates to the new value of the variable assigned to (barring bizarre overloads of operator=). If the assignment happens in a boolean context it will then depend on the type of that value how it is treated. If the value is a bool, it is of course treated as a bool.

  2. Assigning in control structure allowed if multi-line control ...

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.

  3. Why do I get an error when trying to assign a value to a structure

    As Eric's comment points out, you can use structure initialization to initialize the character array with a string constant. invInfo in = {"Kaki", "K1", 8}; Or

  4. Add support for norminette · Issue #3910 · dense-analysis/ale

    Error: SPACE_BEFORE_FUNC (line: 9, col: 12): space before function name Error: ASSIGN_IN_CONTROL (line: 32, col: 21): Assignment in control structure Error: WRONG_SCOPE_COMMENT (line: 48, col: 9): Comment is invalid in this scope Error: TOO_MANY_LINES (line: 64, col: 1): Function has more than 25 lines src/main.h: OK! ... 32, col: 21 ...

  5. PDF Lecture 1: Elementary Programming and Control Structures

    1.5 Assignment operator = In Java, the variable has to be on the left hand side of the assignment operator and the value to be assigned to that variable has to be on the right hand side of the assignment operator: variable = value; For example, you can write: int radius; radius = 5;} but NOT 5 = radius; // This is WRONG

  6. Control Structures in Programming Languages

    Control Structures are just a way to specify flow of control in programs. Any algorithm or program can be more clear and understood if they use self-contained modules called as logic or control structures. It basically analyzes and chooses in which direction a program flows based on certain parameters or conditions. There are three basic types ...

  7. 4. Control Structures

    Control Structures — The Book of C (version 2022.08) 4. Control Structures ¶. In this chapter, we encounter the set of "control" structures in C, such as conditional statements and looping constructs. As a preview, the control structures in C are nearly identical to those found in Java (since Java syntax is heavily based on C), and bear ...

  8. PDF Chapter 2 Assignment and Control

    Assignments and control structures are essential tools tha.t help us to perform this task. Assign­ ments give new values to variables. Control structures use results to control the order in which computations are performed. The control structures that TUring provides are sequence: do one thing after

  9. PDF Control Structures

    a control structure with a different syntax (ADA) -- don't evaluate C2. if C1 and then C2 then -- if C1 is false if C1 or else C2 then -- if C1 is true. Multi-way Selection. Case statement needed when there are many possibilities "at the same logical level" (i.e. depending on the same condition) case Next_Char is.

  10. Assigning Contracts in the Context of M&A Transactions

    Courts will generally enforce these types of comprehensive anti-assignment clauses and conclude that consummation of a change of control transaction without consent is a breach of contract. Accordingly, to assign contracts with comprehensive anti-assignment provisions, the target must seek the consent of the counterparties to each such contract.

  11. Control Structures

    This section demonstrates Scala 3 control structures. for expressions. The for keyword has even more power: When you use the yield keyword instead of do, you create for expressions which are used to calculate and yield results.. A few examples demonstrate this. Using the same ints list as the previous example, this code creates a new list, where the value of each element in the new list is ...

  12. Structure Assignment (GNU C Language Manual)

    15.13 Structure Assignment. Assignment operating on a structure type copies the structure. The left and right operands must have the same type. Here is an example: Notionally, assignment on a structure type works by copying each of the fields. Thus, if any of the fields has the const qualifier, that structure type does not allow assignment:

  13. error Structure assignment to non-structure object

    Dear, I am a beginner in programming matlab. In looking around, I have come across a function which looks like: for j=1: FUE_Num_eachFemto for i=1:HeNB_Num/4 %Generates Femtocell 1 ...

  14. Why do I get: "error: assignment to expression with array type"

    Then, correcting the data type, considering the char array is used, In the first case, arr = "Hello"; is an assignment, which is not allowed with an array type as LHS of assignment. OTOH, char arr[10] = "Hello"; is an initialization statement, which is perfectly valid statement. edited Oct 28, 2022 at 14:48. knittl.

  15. c

    0. I have the following code, which I read and read many times and it always appears to be okay, but the compiler says: error: incompatible types when assigning to type 'struct Type [10]' from type 'Type'. This is the code: int a; int b; Type (*typeArray)[10]; Type typeNewValue; type2Variable->typeArray[0] = typeNewValue; /* This throws the ...

  16. Error on assigning an ACL in Oracle Database

    With the system user (conn system/PASS) I am trying to create and assingning an ACL in Oracle, but I am getting the following error: ERROR line 1: ORA-24244: INVALID HOST OR PORT FOR ACCESS CONTROL LIST (ACL) ORA-06512: em "SYS.DBMS_NETWORK_ACL_ADMIN", line 1343. ORA-06512: em "SYS.DBMS_NETWORK_ACL_ADMIN", line 724.

  17. How to assign value to Struct properties in C

    I copied what you have done above moving my initialisation and assignment in the main() and getting this erors: error: request for member 'x' in something not a structure or union snake.c:283: error: request for member 'y' in something not a structure or union -

  18. incompatible types when assigning to type struct * from struct

    Incompatible types when assigning to type PERSON * from type PERSON. , because that's in fact what you are trying to do, given your declaration of function read_array(). From implementation and use, it appears that you want that function to return a pointer to a structure rather than a copy of the structure. That would be.